Submission #992669
Source Code Expand
#include<cstdio> #include<algorithm> using namespace std; const int MA = 100100; int cnt[100100]; int M; int calc(int r){ if(r * 2 == M || r == 0){ int all = 0; for(int i = r; i < MA; i += M){ all += cnt[i]; } return all / 2; } int l1 = 0, dif1 = 0; int all1 = 0; for(int i = r; i < MA; i += M){ if(cnt[i] % 2 == 1) l1++; all1 += cnt[i]; dif1 += cnt[i] / 2; } int l2 = 0, dif2 = 0; int all2 = 0; for(int i = (M - r); i < MA; i += M){ if(cnt[i] % 2 == 1) l2++; all2 += cnt[i]; dif2 += cnt[i] / 2; } int r1 = l1 + dif1 * 2; int r2 = l2 + dif2 * 2; int all = all1 + all2; if((all1 + all2) % 2 == 1){ all--; if(l1 < l2){ l2--; r2--; }else{ l1--; r1--; } } if(r1 < l2){ return (all - (l2 - r1)) / 2; }else if(r2 < l1){ return (all - (l1 - r2)) / 2; }else{ return all / 2; } } int solve(){ int ans = 0; for(int i = 0; i * 2 <= M; ++i){ ans += calc(i); } return ans; } void input(){ int N; scanf("%d%d", &N, &M); for(int i = 0; i < N; ++i){ int x; scanf("%d", &x); cnt[x]++; } } int main(){ input(); int ans = solve(); printf("%d\n", ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Pair Cards |
User | wo01 |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 1218 Byte |
Status | AC |
Exec Time | 12 ms |
Memory | 640 KB |
Compile Error
./Main.cpp: In function ‘void input()’: ./Main.cpp:65:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d", &N, &M); ^ ./Main.cpp:68:18: 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 | 128 KB |
01-02.txt | AC | 12 ms | 640 KB |
01-03.txt | AC | 11 ms | 512 KB |
01-04.txt | AC | 12 ms | 512 KB |
01-05.txt | AC | 12 ms | 512 KB |
01-06.txt | AC | 12 ms | 512 KB |
01-07.txt | AC | 12 ms | 512 KB |
01-08.txt | AC | 12 ms | 512 KB |
01-09.txt | AC | 12 ms | 512 KB |
01-10.txt | AC | 12 ms | 512 KB |
01-11.txt | AC | 12 ms | 512 KB |
01-12.txt | AC | 11 ms | 256 KB |
01-13.txt | AC | 11 ms | 128 KB |
01-14.txt | AC | 12 ms | 640 KB |
01-15.txt | AC | 12 ms | 512 KB |
01-16.txt | AC | 12 ms | 512 KB |
01-17.txt | AC | 12 ms | 512 KB |
01-18.txt | AC | 12 ms | 512 KB |
01-19.txt | AC | 12 ms | 512 KB |
01-20.txt | AC | 12 ms | 512 KB |
01-21.txt | AC | 11 ms | 512 KB |
01-22.txt | AC | 11 ms | 512 KB |
01-23.txt | AC | 12 ms | 512 KB |
01-24.txt | AC | 12 ms | 640 KB |
01-25.txt | AC | 12 ms | 512 KB |
01-26.txt | AC | 12 ms | 512 KB |
01-27.txt | AC | 7 ms | 384 KB |
01-28.txt | AC | 3 ms | 512 KB |
01-29.txt | AC | 2 ms | 512 KB |
01-30.txt | AC | 2 ms | 256 KB |
sample-01.txt | AC | 2 ms | 128 KB |
sample-02.txt | AC | 2 ms | 128 KB |