Submission #992313
Source Code Expand
#include <cstdio> #include <cassert> #include <set> #include <map> #include <vector> using namespace std; map<int, map<int, int>> byrem; const int N = 100500; bool was[N]; int sum(map<int, int> M) { int s = 0; for (auto pr : M) s += pr.second; return s; } int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { int x; scanf("%d", &x); byrem[x % m][x]++; } int ans = 0; for (int a = 0; a < m; a++) { int b = (m - a) % m; if (was[a] || was[b]) continue; was[a] = was[b] = true; if (a != b) { auto A = byrem[a]; auto B = byrem[b]; set<int> eA, oA; set<int> eB, oB; for (auto pr : A) { ((pr.second % 2) ? oA : eA).insert(pr.first); } for (auto pr : B) { ((pr.second % 2) ? oB : eB).insert(pr.first); } while (oA.size() > 0 && oB.size() > 0) { int x = *oA.begin(); int y = *oB.begin(); assert(A.count(x)); assert(B.count(y)); A[x]--; B[y]--; oA.erase(oA.begin()); oB.erase(oB.begin()); eA.insert(x); eB.insert(y); ans++; } if (!oB.empty()) { A.swap(B); oA.swap(oB); eA.swap(eB); } int sB = sum(B); int sA = sum(A); if ((int)oA.size() <= sB) { ans += (sA + sB) / 2; } else { ans += (sA + sB - (oA.size() - sB)) / 2; } } else { int s = sum(byrem[a]); ans += s / 2; } } printf("%d\n", ans); }
Submission Info
Submission Time | |
---|---|
Task | D - Pair Cards |
User | Zlobober |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 1941 Byte |
Status | AC |
Exec Time | 107 ms |
Memory | 14336 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:22:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d %d", &n, &m); ^ ./Main.cpp:25:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &x); ^
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 | 2 ms | 256 KB |
01-02.txt | AC | 48 ms | 6144 KB |
01-03.txt | AC | 47 ms | 4736 KB |
01-04.txt | AC | 65 ms | 8192 KB |
01-05.txt | AC | 62 ms | 6912 KB |
01-06.txt | AC | 64 ms | 4608 KB |
01-07.txt | AC | 64 ms | 3712 KB |
01-08.txt | AC | 62 ms | 3328 KB |
01-09.txt | AC | 60 ms | 3328 KB |
01-10.txt | AC | 65 ms | 7040 KB |
01-11.txt | AC | 90 ms | 12672 KB |
01-12.txt | AC | 13 ms | 256 KB |
01-13.txt | AC | 27 ms | 4352 KB |
01-14.txt | AC | 58 ms | 7296 KB |
01-15.txt | AC | 105 ms | 9600 KB |
01-16.txt | AC | 86 ms | 5376 KB |
01-17.txt | AC | 90 ms | 4992 KB |
01-18.txt | AC | 80 ms | 5248 KB |
01-19.txt | AC | 74 ms | 6144 KB |
01-20.txt | AC | 107 ms | 14336 KB |
01-21.txt | AC | 22 ms | 512 KB |
01-22.txt | AC | 23 ms | 512 KB |
01-23.txt | AC | 23 ms | 384 KB |
01-24.txt | AC | 24 ms | 512 KB |
01-25.txt | AC | 33 ms | 3328 KB |
01-26.txt | AC | 52 ms | 9856 KB |
01-27.txt | AC | 67 ms | 12032 KB |
01-28.txt | AC | 33 ms | 9856 KB |
01-29.txt | AC | 13 ms | 3968 KB |
01-30.txt | AC | 33 ms | 9728 KB |
sample-01.txt | AC | 2 ms | 256 KB |
sample-02.txt | AC | 2 ms | 256 KB |