Submission #992535
Source Code Expand
#include <bits/stdc++.h> #define REP(i,n) for (int i=0; i<(int)(n); ++i) #define FOR(i,n,m) for (int i=n; i<(int)(m); ++i) #define ALL(x) x.begin(), x.end() #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define in(i, n) (0 <= (i) && (i) < (n)) #define on(bit, i) (((bit >> i) & 1) == 1) using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef long double ld; const int INF = 1e9+7; int N, M; map<int, int> mp; int main(void) { cin >> N >> M; REP(i, N) { int t; cin >> t; mp[t]++; } vector<int> pcnt(M + 1), cnt(M + 1); for (auto p : mp) { cnt[p.first % M] += p.second; pcnt[p.first % M] += p.second / 2; } int res = 0; for (int i = 0; i < M; i++) { int j = (M - i + M) % M; if (i > j) continue; if (i == j) { res += cnt[i] / 2; //cout << i << " " << cnt[i] / 2 << endl; } else { if (cnt[i] < cnt[j]) { int rest = cnt[j] - cnt[i]; res += cnt[i] + min(pcnt[j], rest / 2); //cout << i << " " << cnt[i] + min(pcnt[j], rest / 2) << endl; } else { int rest = cnt[i] - cnt[j]; res += cnt[j] + min(pcnt[i], rest / 2); //cout << i << " " << cnt[j] + min(pcnt[i], rest / 2) << endl; } }; } cout << res << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Pair Cards |
User | takisekazuki |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 1313 Byte |
Status | AC |
Exec Time | 70 ms |
Memory | 5760 KB |
Judge Result
Set Name | sample | all | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
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 | 60 ms | 3200 KB |
01-03.txt | AC | 60 ms | 3200 KB |
01-04.txt | AC | 60 ms | 3200 KB |
01-05.txt | AC | 60 ms | 3200 KB |
01-06.txt | AC | 60 ms | 3328 KB |
01-07.txt | AC | 60 ms | 3200 KB |
01-08.txt | AC | 60 ms | 3200 KB |
01-09.txt | AC | 59 ms | 3200 KB |
01-10.txt | AC | 60 ms | 3584 KB |
01-11.txt | AC | 61 ms | 3968 KB |
01-12.txt | AC | 31 ms | 256 KB |
01-13.txt | AC | 31 ms | 640 KB |
01-14.txt | AC | 68 ms | 4992 KB |
01-15.txt | AC | 68 ms | 4992 KB |
01-16.txt | AC | 68 ms | 4864 KB |
01-17.txt | AC | 68 ms | 4992 KB |
01-18.txt | AC | 68 ms | 4992 KB |
01-19.txt | AC | 70 ms | 4992 KB |
01-20.txt | AC | 70 ms | 5760 KB |
01-21.txt | AC | 39 ms | 384 KB |
01-22.txt | AC | 39 ms | 384 KB |
01-23.txt | AC | 39 ms | 384 KB |
01-24.txt | AC | 39 ms | 384 KB |
01-25.txt | AC | 39 ms | 640 KB |
01-26.txt | AC | 41 ms | 1152 KB |
01-27.txt | AC | 35 ms | 3328 KB |
01-28.txt | AC | 6 ms | 1152 KB |
01-29.txt | AC | 4 ms | 640 KB |
01-30.txt | AC | 4 ms | 1024 KB |
sample-01.txt | AC | 3 ms | 256 KB |
sample-02.txt | AC | 3 ms | 256 KB |