Submission #993137
Source Code Expand
#include<bits/stdc++.h> using namespace std; int main() { int N, M; map< int, int > xs[100001]; int sum[100001] = {}; cin >> N >> M; for(int i = 0; i < N; i++) { int X; cin >> X; xs[X % M][X]++; sum[X % M]++; } int ret = sum[0] / 2; for(int i = 1; i <= M - i; i++) { if(i == M - i) { ret += sum[i] / 2; break; } int one1 = 0, one2 = 0; priority_queue< int > p, q; for(auto &a : xs[i]) { if(a.second / 2 > 0) p.push(a.second / 2); one1 += a.second % 2; } for(auto &a : xs[M - i]) { if(a.second / 2 > 0) q.push(a.second / 2); one2 += a.second % 2; } while(one1 > 0 || one2 > 0) { if(one1 == 0) { if(p.empty()) break; int k = p.top() - 1; p.pop(); if(k > 0) p.push(k); one1++; } else { --one1; } if(one2 == 0) { if(q.empty()) break; int k = q.top() - 1; q.pop(); if(k > 0) q.push(k); one2++; } else { one2--; } ++ret; } while(!p.empty()) { ret += p.top(); p.pop(); } while(!q.empty()) { ret += q.top(); q.pop(); } } cout << ret << endl; }
Submission Info
Submission Time | |
---|---|
Task | D - Pair Cards |
User | ei13333 |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 1318 Byte |
Status | AC |
Exec Time | 81 ms |
Memory | 10112 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 | 8 ms | 5376 KB |
01-02.txt | AC | 66 ms | 8320 KB |
01-03.txt | AC | 65 ms | 8320 KB |
01-04.txt | AC | 67 ms | 8448 KB |
01-05.txt | AC | 67 ms | 8320 KB |
01-06.txt | AC | 66 ms | 8320 KB |
01-07.txt | AC | 65 ms | 8320 KB |
01-08.txt | AC | 61 ms | 8320 KB |
01-09.txt | AC | 59 ms | 8320 KB |
01-10.txt | AC | 51 ms | 8320 KB |
01-11.txt | AC | 49 ms | 8320 KB |
01-12.txt | AC | 36 ms | 5376 KB |
01-13.txt | AC | 36 ms | 5376 KB |
01-14.txt | AC | 72 ms | 9984 KB |
01-15.txt | AC | 74 ms | 9984 KB |
01-16.txt | AC | 72 ms | 9984 KB |
01-17.txt | AC | 81 ms | 10112 KB |
01-18.txt | AC | 63 ms | 9984 KB |
01-19.txt | AC | 58 ms | 9984 KB |
01-20.txt | AC | 51 ms | 9984 KB |
01-21.txt | AC | 45 ms | 5504 KB |
01-22.txt | AC | 45 ms | 5504 KB |
01-23.txt | AC | 43 ms | 5504 KB |
01-24.txt | AC | 40 ms | 5504 KB |
01-25.txt | AC | 38 ms | 5504 KB |
01-26.txt | AC | 38 ms | 5504 KB |
01-27.txt | AC | 28 ms | 7680 KB |
01-28.txt | AC | 10 ms | 5504 KB |
01-29.txt | AC | 8 ms | 5376 KB |
01-30.txt | AC | 8 ms | 5376 KB |
sample-01.txt | AC | 8 ms | 5376 KB |
sample-02.txt | AC | 8 ms | 5376 KB |