Submission #1695566
Source Code Expand
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int x[100010], cnt[100010], cnt2[100010];
VI g[100010];
PII a[100010];
signed main(void)
{
int n, m;
cin >> n >> m;
REP(i, n) {
cin >> x[i];
cnt[x[i]%m]++;
g[x[i]%m].PB(x[i]);
}
REP(i, m) {
if(g[i].size() == 0) continue;
sort(ALL(g[i]));
int c = 1;
// for(int j: g[i]) cout << j << " "; cout << endl;
FOR(j, 1, g[i].size()) {
if(g[i][j] == g[i][j-1]) {
c++;
} else {
a[i].first += c%2==1;
a[i].second += c/2;
c = 1;
}
}
a[i].first += c%2==1;
a[i].second += c/2;
}
// REP(i, m) cout << a[i].first << "," << a[i].second << " "; cout << endl;
int ret = 0;
REP(i, m/2+1) {
if(i == 0 || i*2 == m) {
ret += cnt[i]/2;
} else {
int tmp = min(cnt[i], cnt[m-i]);
// cout << tmp << " ";
ret += tmp;
if(a[i].first >= tmp) ret += a[i].second;
else ret += max(0LL, a[i].second - (tmp - a[i].first - 1)/2 - 1);
if(a[m-i].first >= tmp) ret += a[m-i].second;
else ret += max(0LL, a[m-i].second - (tmp - a[m-i].first - 1)/2 - 1);
}
// cout << i << " " << ret << endl;
}
cout << ret << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Pair Cards |
User |
ferin_tech |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
2054 Byte |
Status |
AC |
Exec Time |
41 ms |
Memory |
9600 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, sample-01.txt, sample-02.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
2 ms |
4864 KB |
01-02.txt |
AC |
38 ms |
6008 KB |
01-03.txt |
AC |
38 ms |
5852 KB |
01-04.txt |
AC |
38 ms |
6076 KB |
01-05.txt |
AC |
37 ms |
5824 KB |
01-06.txt |
AC |
37 ms |
6272 KB |
01-07.txt |
AC |
36 ms |
5888 KB |
01-08.txt |
AC |
35 ms |
6144 KB |
01-09.txt |
AC |
36 ms |
6144 KB |
01-10.txt |
AC |
40 ms |
7296 KB |
01-11.txt |
AC |
41 ms |
8576 KB |
01-12.txt |
AC |
33 ms |
6008 KB |
01-13.txt |
AC |
33 ms |
6008 KB |
01-14.txt |
AC |
37 ms |
5852 KB |
01-15.txt |
AC |
37 ms |
5996 KB |
01-16.txt |
AC |
36 ms |
6272 KB |
01-17.txt |
AC |
35 ms |
6016 KB |
01-18.txt |
AC |
36 ms |
6656 KB |
01-19.txt |
AC |
38 ms |
6400 KB |
01-20.txt |
AC |
39 ms |
9600 KB |
01-21.txt |
AC |
36 ms |
5832 KB |
01-22.txt |
AC |
36 ms |
5976 KB |
01-23.txt |
AC |
35 ms |
6144 KB |
01-24.txt |
AC |
34 ms |
6144 KB |
01-25.txt |
AC |
35 ms |
6784 KB |
01-26.txt |
AC |
37 ms |
7808 KB |
01-27.txt |
AC |
21 ms |
7168 KB |
01-28.txt |
AC |
5 ms |
6528 KB |
01-29.txt |
AC |
3 ms |
5504 KB |
01-30.txt |
AC |
3 ms |
4864 KB |
sample-01.txt |
AC |
2 ms |
4864 KB |
sample-02.txt |
AC |
2 ms |
4864 KB |