Submission #994535
Source Code Expand
#include <iostream> #include <sstream> #include <vector> #include <string> #include <cstring> #include <algorithm> #include <queue> #include <map> #include <set> #define REP(i,k,n) for(int i=k;i<n;i++) #define rep(i,n) for(int i=0;i<n;i++) #define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++) #define INF 1<<30 #define mp make_pair using namespace std; typedef long long ll; typedef pair<ll, ll> P; int main() { int n, m; cin >> n >> m; vector<int> v(n); rep(i, n) cin >> v[i]; sort(v.begin(), v.end()); map<int, int> ma; rep(i, n) { ma[v[i]]++; } priority_queue<P, vector<P>, greater<P> > que[100005]; each(it, ma) { int mm = it->first % m; if(it->second % 2 == 0) { que[mm].push(mp(it->second, it->first)); } else { que[mm].push(mp((-1) * it->second, it->first)); } // cout << it->first << " " << it-> second << " m;" << mm << endl;; } int ans = 0; REP(i, 1, m / 2 + (m % 2 != 0)) { //0は例外 int j = m - i; // cout << "----------in for:" << i << " " << j << endl; while(que[i].size() && que[j].size()) { P p1 = que[i].top(); que[i].pop(); P p2 = que[j].top(); que[j].pop(); if(p1.first < 0) { p1.first *= -1; } if(p2.first < 0) { p2.first *= -1; } // cout << "p1:" << p1.first << " " << p1.second << endl; // cout << "p2:" << p2.first << " " << p2.second << endl; if(p1.first >= p2.first) { ans += p2.first; ma[p1.second] -= p2.first; ma[p2.second] -= p2.first; p1.first -= p2.first; p2.first = 0; if(p1.first > 0) { if(p1.first % 2 == 0) { que[i].push(mp(p1.first, p1.second)); } else { que[i].push(mp((-1) * p1.first, p1.second)); } // cout << " -- update:" << p1.first << " " << p1.second << endl; } } else { ans += p1.first; ma[p1.second] -= p1.first; ma[p2.second] -= p1.first; p2.first -= p1.first; p1.first = 0; if(p2.first > 0) { if(p2.first % 2 == 0) { que[j].push(mp(p2.first, p2.second)); } else { que[j].push(mp((-1) * p2.first, p2.second)); } // cout << " -- update:" << p2.first << " " << p2.second << endl; } } } } int sum = 0; while(que[0].size()) { P p = que[0].top(); que[0].pop(); if(p.first < 0) { p.first *= -1; } sum += p.first; ma[p.second] = 0; } ans += sum / 2; each(it, ma) { // cout << "end:" << it->first << " " << it->second << endl; if(it->second >= 2) { ans += it->second / 2; } } cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Pair Cards |
User | Ry0u_ |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2655 Byte |
Status | WA |
Exec Time | 96 ms |
Memory | 11520 KB |
Judge Result
Set Name | sample | all | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | 6 ms | 3328 KB |
01-02.txt | AC | 74 ms | 7932 KB |
01-03.txt | WA | 69 ms | 7840 KB |
01-04.txt | AC | 76 ms | 7932 KB |
01-05.txt | WA | 74 ms | 7800 KB |
01-06.txt | AC | 78 ms | 8064 KB |
01-07.txt | WA | 79 ms | 8192 KB |
01-08.txt | AC | 81 ms | 7936 KB |
01-09.txt | WA | 80 ms | 8320 KB |
01-10.txt | WA | 73 ms | 8448 KB |
01-11.txt | AC | 71 ms | 8704 KB |
01-12.txt | AC | 35 ms | 3712 KB |
01-13.txt | AC | 35 ms | 3712 KB |
01-14.txt | WA | 80 ms | 10228 KB |
01-15.txt | AC | 89 ms | 10276 KB |
01-16.txt | WA | 91 ms | 10880 KB |
01-17.txt | AC | 96 ms | 10368 KB |
01-18.txt | AC | 93 ms | 11392 KB |
01-19.txt | AC | 90 ms | 10368 KB |
01-20.txt | AC | 89 ms | 11520 KB |
01-21.txt | WA | 42 ms | 3968 KB |
01-22.txt | AC | 42 ms | 4096 KB |
01-23.txt | WA | 42 ms | 4096 KB |
01-24.txt | WA | 42 ms | 4096 KB |
01-25.txt | AC | 42 ms | 4096 KB |
01-26.txt | AC | 42 ms | 4096 KB |
01-27.txt | AC | 37 ms | 7424 KB |
01-28.txt | AC | 8 ms | 3584 KB |
01-29.txt | AC | 6 ms | 3456 KB |
01-30.txt | AC | 6 ms | 3328 KB |
sample-01.txt | AC | 6 ms | 3328 KB |
sample-02.txt | WA | 6 ms | 3328 KB |