Submission #7917480


Source Code Expand

Copy
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin>>n>>m;
    int lim = 1e+5 + 10;
    vector<int> x(lim,0);
    vector<int> count_mod(lim,0), count_mod2(lim,0);
    rep(i,n){
        int a;
        cin>>a;
        x[a]++;
    }
    rep(i,lim){
        count_mod[i%m] += x[i]/2;
        count_mod2[i%m] += x[i]%2;
    }
    vector<bool> checked(m,false);
    int res=0;
    rep(i,m){
        if(i==0||i*2==m){
            res += count_mod[i]+count_mod2[i]/2;
            continue;
        }
        if(!checked[i]){
            DEBUG{
                printf("set: %d, %d\n",i,m-i);
                printf(" %d, %d\n",count_mod[i],count_mod2[i]);
                printf(" %d, %d\n",count_mod[m-i],count_mod2[m-i]);
            }
            int tmp = min(count_mod2[i], count_mod2[m-i]);
            res += tmp;
            if(count_mod2[i]<count_mod2[m-i]){
                tmp = count_mod2[m-i]-tmp;
                res += min(count_mod[i]*2, tmp);
                res += max((count_mod[i]*2-tmp)/2,0);
                res += count_mod[m-i];
            }else{
                tmp = count_mod2[i]-tmp;
                res += min(count_mod[m-i]*2, tmp);
                res += max((count_mod[m-i]*2-tmp)/2,0);
                res += count_mod[i];
            }
        }
        checked[i] = checked[m-i] = true;
    }
    cout << res << endl;
    return 0;
}

Submission Info

Submission Time
Task D - Pair Cards
User yak
Language C++14 (GCC 5.4.1)
Score 700
Code Size 2037 Byte
Status
Exec Time 11 ms
Memory 1408 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 700 / 700
Status
Test Cases sample-01.txt, sample-02.txt 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, sample-01.txt, sample-02.txt
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, sample-01.txt, sample-02.txt
Case Name Status Exec Time Memory
01-01.txt 2 ms 1408 KB
01-02.txt 10 ms 1408 KB
01-03.txt 10 ms 1408 KB
01-04.txt 10 ms 1408 KB
01-05.txt 10 ms 1408 KB
01-06.txt 10 ms 1408 KB
01-07.txt 10 ms 1408 KB
01-08.txt 10 ms 1408 KB
01-09.txt 10 ms 1408 KB
01-10.txt 10 ms 1408 KB
01-11.txt 11 ms 1408 KB
01-12.txt 10 ms 1408 KB
01-13.txt 10 ms 1408 KB
01-14.txt 10 ms 1408 KB
01-15.txt 10 ms 1408 KB
01-16.txt 10 ms 1408 KB
01-17.txt 10 ms 1408 KB
01-18.txt 10 ms 1408 KB
01-19.txt 10 ms 1408 KB
01-20.txt 11 ms 1408 KB
01-21.txt 10 ms 1408 KB
01-22.txt 10 ms 1408 KB
01-23.txt 10 ms 1408 KB
01-24.txt 10 ms 1408 KB
01-25.txt 10 ms 1408 KB
01-26.txt 10 ms 1408 KB
01-27.txt 7 ms 1408 KB
01-28.txt 3 ms 1408 KB
01-29.txt 3 ms 1408 KB
01-30.txt 3 ms 1408 KB
sample-01.txt 2 ms 1408 KB
sample-02.txt 2 ms 1408 KB