Submission #1003666


Source Code Expand

# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vll vector < ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define pdd pair < db , db >
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n,m;
    fi>>n>>m;
    static int cnt[1 << 20];
    static map < int , int > s[1 << 20];
    int v;
    for (int i = 1;i <= n;++i)
        fi>>v,s[v % m][v]++,cnt[v % m]++;;
    ll ans = 0;
    for (int i = 0;i + i <= m;++i)
    {
        int a = i;
        int b = (m - i) % m;
        if (a == b)
            ans += cnt[i] / 2;
        else
        {
            if (cnt[a] < cnt[b]) swap(a,b);
            for (auto &it : s[a])
                if ((it.y & 1) && cnt[b])
                    --cnt[a],--cnt[b],++ans,--it.y;
            for (auto &it : s[a])
            {
                int can = min(cnt[b],it.y);
                cnt[b] -= can;
                it.y -= can;
                ans += can;
                ans += it.y / 2;
            }
        }
    }
    fo << ans << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Submission Info

Submission Time
Task D - Pair Cards
User reality
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1631 Byte
Status AC
Exec Time 128 ms
Memory 54528 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 32
Set Name Test Cases
sample sample-01.txt, sample-02.txt
all sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt
Case Name Status Exec Time Memory
01-01.txt AC 55 ms 49408 KB
01-02.txt AC 118 ms 52352 KB
01-03.txt AC 118 ms 52352 KB
01-04.txt AC 118 ms 52352 KB
01-05.txt AC 118 ms 52352 KB
01-06.txt AC 118 ms 52352 KB
01-07.txt AC 117 ms 52352 KB
01-08.txt AC 112 ms 52352 KB
01-09.txt AC 109 ms 52352 KB
01-10.txt AC 103 ms 52480 KB
01-11.txt AC 104 ms 52736 KB
01-12.txt AC 88 ms 49408 KB
01-13.txt AC 88 ms 49408 KB
01-14.txt AC 128 ms 54144 KB
01-15.txt AC 127 ms 54144 KB
01-16.txt AC 125 ms 54144 KB
01-17.txt AC 122 ms 54144 KB
01-18.txt AC 116 ms 54144 KB
01-19.txt AC 112 ms 54144 KB
01-20.txt AC 107 ms 54528 KB
01-21.txt AC 97 ms 49536 KB
01-22.txt AC 96 ms 49536 KB
01-23.txt AC 95 ms 49536 KB
01-24.txt AC 91 ms 49536 KB
01-25.txt AC 90 ms 49664 KB
01-26.txt AC 90 ms 49920 KB
01-27.txt AC 81 ms 52096 KB
01-28.txt AC 58 ms 49920 KB
01-29.txt AC 56 ms 49536 KB
01-30.txt AC 56 ms 49408 KB
sample-01.txt AC 56 ms 49408 KB
sample-02.txt AC 55 ms 49408 KB