Submission #7607107
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));
int main(){
long long M;
long long N;
scanf("%lld",&N);
vector<long long> X(N-1+1);
scanf("%lld",&M);
map<ll, ll> m;
for(int i = 0 ; i <= N-1 ; i++){
scanf("%lld",&X[i]);
m[X[i]]++;
}
map<ll, ll> m1, m2;
rep(i, 100001) {
m1[i%M] += m[i]%2;
m2[i%M] += m[i]-m[i]%2;
}
ll res = 0;
rep(i, M/2+1) {
// cout << i << ": " << m1[i] << " " << (M-i)%M << ": " << m1[(M-i)%M] << endl;
// cout << i << ": " << m2[i] << " " << (M-i)%M << ": " << m2[(M-i)%M] << endl;
if (i != (M-i)%M) {
ll b1 = min(m1[i],m1[(M-i)%M]);
// cout << i << ": " << m1[i] << " " << (M-i)%M << ": " << m1[(M-i)%M] << endl;
// cout << i << ": " << m2[i] << " " << (M-i)%M << ": " << m2[(M-i)%M] << endl;
res += b1;
m1[i] -= b1;
m1[(M-i)%M] -= b1;
} else {
ll b1 = m1[i]/2;
res += b1;
m1[i] -= b1;
// cout << i << ": " << m1[i] << " " << (M-i)%M << ": " << m1[(M-i)%M] << endl;
// cout << i << ": " << m2[i] << " " << (M-i)%M << ": " << m2[(M-i)%M] << endl;
}
// cout << i << ": " << m1[i] << " " << (M-i)%M << ": " << m1[(M-i)%M] << endl;
// cout << i << ": " << m2[i] << " " << (M-i)%M << ": " << m2[(M-i)%M] << endl;
if (i != (M-i)%M && m1[i] > 0) {
ll b2 = min(m1[i],m2[(M-i)%M]);
res += b2;
m1[i] -= b2;
m2[(M-i)%M] -= b2;
}
if (i != (M-i)%M && m1[(M-i)%M] > 0) {
ll b2 = min(m1[(M-i)%M],m2[i]);
res += b2;
m1[(M-i)%M] -= b2;
m2[i] -= b2;
}
// cout << i << ": " << m1[i] << " " << (M-i)%M << ": " << m1[(M-i)%M] << endl;
// cout << i << ": " << m2[i] << " " << (M-i)%M << ": " << m2[(M-i)%M] << endl;
}
rep(i, M) {
res += m2[i]/2;
}
cout << res << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Pair Cards |
User |
dn154 |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
2414 Byte |
Status |
AC |
Exec Time |
191 ms |
Memory |
19840 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:27:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&N);
^
./Main.cpp:29:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&M);
^
./Main.cpp:32:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&X[i]);
^
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, sample-01.txt, sample-02.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
58 ms |
6528 KB |
01-02.txt |
AC |
64 ms |
7296 KB |
01-03.txt |
AC |
65 ms |
7296 KB |
01-04.txt |
AC |
66 ms |
7296 KB |
01-05.txt |
AC |
67 ms |
7296 KB |
01-06.txt |
AC |
68 ms |
7296 KB |
01-07.txt |
AC |
71 ms |
9088 KB |
01-08.txt |
AC |
75 ms |
7296 KB |
01-09.txt |
AC |
77 ms |
7552 KB |
01-10.txt |
AC |
96 ms |
12288 KB |
01-11.txt |
AC |
133 ms |
19840 KB |
01-12.txt |
AC |
73 ms |
7296 KB |
01-13.txt |
AC |
112 ms |
12800 KB |
01-14.txt |
AC |
69 ms |
7296 KB |
01-15.txt |
AC |
70 ms |
7296 KB |
01-16.txt |
AC |
74 ms |
7296 KB |
01-17.txt |
AC |
77 ms |
7296 KB |
01-18.txt |
AC |
81 ms |
7680 KB |
01-19.txt |
AC |
92 ms |
8832 KB |
01-20.txt |
AC |
191 ms |
19840 KB |
01-21.txt |
AC |
48 ms |
7296 KB |
01-22.txt |
AC |
53 ms |
7296 KB |
01-23.txt |
AC |
57 ms |
7296 KB |
01-24.txt |
AC |
62 ms |
7424 KB |
01-25.txt |
AC |
75 ms |
11008 KB |
01-26.txt |
AC |
108 ms |
19840 KB |
01-27.txt |
AC |
190 ms |
19328 KB |
01-28.txt |
AC |
97 ms |
19072 KB |
01-29.txt |
AC |
63 ms |
11392 KB |
01-30.txt |
AC |
155 ms |
18944 KB |
sample-01.txt |
AC |
61 ms |
6528 KB |
sample-02.txt |
AC |
61 ms |
6528 KB |