Submission #1003398


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int N, M;
const int MAX = 1e5 + 1;


int main()
{
    ios::sync_with_stdio(false);

    cin >> N >> M;
    vector<map<int, int>> cnt(M);
    vector<int> cnt_all(M);
    
    rep(i, N) {
        int X; cin >> X;
        cnt[X % M][X]++;
        cnt_all[X % M]++;
    }

    int ans = 0;
    for (int i=0; i<=M/2; i++) {
        if (i == 0 || i*2 == M) {
            ans += cnt_all[i] / 2;
        } else {
            int a = i, b = M - i;
            if (cnt_all[a] < cnt_all[b]) swap(a, b);
            int ss = cnt_all[a], ts = cnt_all[b];
            int same_match_max = (ss - ts) / 2;
            map<int, int> S = cnt[a];
            for (auto s : S) {
               if (ss > ts && s.second > 1) {
                   int same_match = min(same_match_max, s.second/2);
                   same_match_max -= same_match;
                   ans += same_match;
               } 
            }
            ans += ts;
        }
        // DUMP2(i, ans);
    }

    cout << ans << endl;
}

Submission Info

Submission Time
Task D - Pair Cards
User OUDON
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1554 Byte
Status AC
Exec Time 49 ms
Memory 9984 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 3 ms 256 KB
01-02.txt AC 40 ms 3200 KB
01-03.txt AC 39 ms 3200 KB
01-04.txt AC 42 ms 4224 KB
01-05.txt AC 41 ms 3968 KB
01-06.txt AC 40 ms 3456 KB
01-07.txt AC 39 ms 3328 KB
01-08.txt AC 36 ms 3200 KB
01-09.txt AC 35 ms 3328 KB
01-10.txt AC 28 ms 5248 KB
01-11.txt AC 31 ms 8320 KB
01-12.txt AC 11 ms 256 KB
01-13.txt AC 14 ms 2432 KB
01-14.txt AC 46 ms 4992 KB
01-15.txt AC 49 ms 5888 KB
01-16.txt AC 47 ms 4992 KB
01-17.txt AC 44 ms 4992 KB
01-18.txt AC 39 ms 5120 KB
01-19.txt AC 34 ms 5632 KB
01-20.txt AC 33 ms 9984 KB
01-21.txt AC 20 ms 384 KB
01-22.txt AC 20 ms 512 KB
01-23.txt AC 18 ms 512 KB
01-24.txt AC 15 ms 512 KB
01-25.txt AC 16 ms 1920 KB
01-26.txt AC 21 ms 5504 KB
01-27.txt AC 22 ms 7680 KB
01-28.txt AC 11 ms 5504 KB
01-29.txt AC 5 ms 2304 KB
01-30.txt AC 10 ms 5376 KB
sample-01.txt AC 3 ms 256 KB
sample-02.txt AC 3 ms 256 KB