Submission #13476940


Source Code Expand

Copy
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


void solve(){
    int N, M;
    cin >> N >> M;
    vector<int> X(N);
    vector<int> cnt_mod(M), cnt(101010);
    REP(i,N){
        int x;
        cin >> x;
        cnt_mod[x%M]++;
        cnt[x]++;
    }
    int ans = 0;
    REP(i,M){
        if(i == 0 || i * 2 == M){
            ans += cnt_mod[i] / 2;
            cnt_mod[i] %= 2;
        }
        else{
            int p = min(cnt_mod[i], cnt_mod[M-i]);
            ans += p;
            cnt_mod[i] -= p, cnt_mod[M-i] -= p;
            for(int j=i;j<101010;j+=M){
                if(cnt[j] >= 2){
                    ans += min(cnt_mod[i], cnt[j]) / 2;
                    cnt_mod[i] -= min(cnt_mod[i], cnt[j]) / 2 * 2;
                }
            }
        }
    }
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}

Submission Info

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

Judge Result

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