Submission #993916
Source Code Expand
#include <iostream> #include <algorithm> #include <vector> #include <queue> #include <map> using namespace std; typedef vector<int> VI; typedef vector<VI> VII; typedef map<int, int> MII; typedef vector<MII> VMII; typedef pair<int, int> PII; typedef priority_queue<PII> PQPII; typedef vector<PQPII> VPQPII; #define MP make_pair int main() { int N, M; cin >> N >> M; VMII xss(M); VPQPII pqs(M); for (int i = 0; i < N; i++) { int n; cin >> n; auto& m = xss[n%M]; if (m.count(n)) { m[n]++; } else { m[n] = 1; } } for (int i = 0; i < M; i++) { auto& m = xss[i]; for (auto it = m.begin(); it != m.end(); it++) { pqs[i].push(MP(it->second, it->first)); } } VII yss(M); /* for (int i = 0; i < M; i++) { auto& m = pqs[i]; cout << i; cout << ":"; while (!m.empty()) { auto x = m.top(); m.pop(); cout << x.first << "," << x.second; cout << " "; } cout << endl; } */ for (int i = 0; i < M; i++) { auto& m = pqs[i]; VI a; VI b; while (!m.empty()) { auto x = m.top(); m.pop(); auto num = x.first; auto v = x.second; for (int j = 0; j < num / 2 * 2; j++) { a.push_back(v); } if (num % 2) { b.push_back(v); } } yss[i].insert(yss[i].end(), a.begin(), a.end()); yss[i].insert(yss[i].end(), b.begin(), b.end()); } /* cout << endl; for (int i = 0; i < M; i++) { cout << i << ":"; for (auto x: yss[i]) { cout << x << " "; } cout << endl; } */ int res = 0; for (int i = 0; i <= M/2; i++) { int j = (M-i)%M; auto& ys_i = yss[i]; auto& ys_j = yss[j]; if (i != j) { while (!ys_i.empty() && !ys_j.empty()) { ys_i.pop_back(); ys_j.pop_back(); res++; } } else { while (ys_i.size() >= 2) { ys_i.pop_back(); ys_j.pop_back(); res++; } } } /* cout << endl; for (int i = 0; i < M; i++) { cout << i << ":"; for (auto x: yss[i]) { cout << x << " "; } cout << endl; } */ for (int i = 0; i < M; i++) { const auto& ys_i = yss[i]; for (int j = 0; j < ((int)ys_i.size())-1; j++) { //cout << j << " " << ys_i.size() << endl; if (ys_i[j] == ys_i[j+1]) { res++; j++; } } } cout << res << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Pair Cards |
User | almizaar |
Language | C++14 (Clang 3.8.0) |
Score | 700 |
Code Size | 2551 Byte |
Status | AC |
Exec Time | 134 ms |
Memory | 19072 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 | 7 ms | 888 KB |
01-02.txt | AC | 125 ms | 4732 KB |
01-03.txt | AC | 123 ms | 4384 KB |
01-04.txt | AC | 122 ms | 4420 KB |
01-05.txt | AC | 121 ms | 4352 KB |
01-06.txt | AC | 119 ms | 4352 KB |
01-07.txt | AC | 118 ms | 4352 KB |
01-08.txt | AC | 110 ms | 4352 KB |
01-09.txt | AC | 111 ms | 4608 KB |
01-10.txt | AC | 109 ms | 8832 KB |
01-11.txt | AC | 115 ms | 14976 KB |
01-12.txt | AC | 80 ms | 1528 KB |
01-13.txt | AC | 85 ms | 4600 KB |
01-14.txt | AC | 134 ms | 6396 KB |
01-15.txt | AC | 133 ms | 6252 KB |
01-16.txt | AC | 127 ms | 6272 KB |
01-17.txt | AC | 118 ms | 6400 KB |
01-18.txt | AC | 117 ms | 7168 KB |
01-19.txt | AC | 109 ms | 7552 KB |
01-20.txt | AC | 119 ms | 19072 KB |
01-21.txt | AC | 95 ms | 1268 KB |
01-22.txt | AC | 92 ms | 1024 KB |
01-23.txt | AC | 89 ms | 1152 KB |
01-24.txt | AC | 86 ms | 1280 KB |
01-25.txt | AC | 88 ms | 3584 KB |
01-26.txt | AC | 95 ms | 8960 KB |
01-27.txt | AC | 65 ms | 13568 KB |
01-28.txt | AC | 16 ms | 8448 KB |
01-29.txt | AC | 7 ms | 3456 KB |
01-30.txt | AC | 12 ms | 8064 KB |
sample-01.txt | AC | 2 ms | 256 KB |
sample-02.txt | AC | 2 ms | 256 KB |