Submission #1692741
Source Code Expand
#include <iostream> #include <map> #include <vector> using namespace std; int main() { int N, M; cin >> N >> M; vector<int> p_cnt(M, 0), o_cnt(M, 0); map<int, int> mp; for (int i = 0; i < N; i++) { int X; cin >> X; mp[X] ^= 1; if (mp[X] == 0) { p_cnt[X % M]++; } } for (auto p : mp) o_cnt[p.first % M] += p.second; int ans = 0; for (int i1 = 0; 2 * i1 <= M; i1++) { int i2 = (M - i1) % M; if (i1 == i2) { ans += (2 * p_cnt[i1] + o_cnt[i1]) / 2; } else { int num1 = 2 * p_cnt[i1] + o_cnt[i1], num2 = 2 * p_cnt[i2] + o_cnt[i2]; if (num1 < num2) { swap(num1, num2); swap(p_cnt[i1], p_cnt[i2]); swap(o_cnt[i1], o_cnt[i2]); } ans += min(num1, num2); ans += min(p_cnt[i1], (num1 - num2) / 2); } } cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Pair Cards |
User | myusa |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 1053 Byte |
Status | AC |
Exec Time | 78 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, sample-01.txt, sample-02.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 1 ms | 256 KB |
01-02.txt | AC | 65 ms | 3200 KB |
01-03.txt | AC | 65 ms | 3200 KB |
01-04.txt | AC | 66 ms | 3200 KB |
01-05.txt | AC | 65 ms | 3200 KB |
01-06.txt | AC | 65 ms | 3200 KB |
01-07.txt | AC | 65 ms | 3200 KB |
01-08.txt | AC | 65 ms | 3200 KB |
01-09.txt | AC | 65 ms | 3200 KB |
01-10.txt | AC | 66 ms | 3584 KB |
01-11.txt | AC | 66 ms | 3968 KB |
01-12.txt | AC | 30 ms | 256 KB |
01-13.txt | AC | 30 ms | 640 KB |
01-14.txt | AC | 73 ms | 4992 KB |
01-15.txt | AC | 73 ms | 4992 KB |
01-16.txt | AC | 73 ms | 4992 KB |
01-17.txt | AC | 73 ms | 4992 KB |
01-18.txt | AC | 73 ms | 4992 KB |
01-19.txt | AC | 78 ms | 4992 KB |
01-20.txt | AC | 73 ms | 5760 KB |
01-21.txt | AC | 44 ms | 384 KB |
01-22.txt | AC | 44 ms | 384 KB |
01-23.txt | AC | 44 ms | 384 KB |
01-24.txt | AC | 44 ms | 384 KB |
01-25.txt | AC | 44 ms | 640 KB |
01-26.txt | AC | 45 ms | 1152 KB |
01-27.txt | AC | 35 ms | 3328 KB |
01-28.txt | AC | 4 ms | 1152 KB |
01-29.txt | AC | 2 ms | 640 KB |
01-30.txt | AC | 2 ms | 1024 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |