Submission #7901261
Source Code Expand
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }
namespace init__ {
struct InitIO {
InitIO() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(30);
}
} init_io;
}
#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif
template <typename T>
T make_v(T init) { return init; }
template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
return V<decltype(rec)>(s, rec);
#undef rec
}
int main() {
ll N, M;
cin >> N >> M;
VV<ll> modm(M);
V<ll> cnt(M);
for(ll i = 0; i < N; i++) {
ll X;
cin >> X;
modm[X % M].push_back(X);
}
for(ll i = 0; i < M; i++) {
sort(ALL(modm[i]));
ll pre = -1;
ll cnt_e = 0;
for(ll e : modm[i]) {
if(pre == e) {
cnt_e++;
} else {
cnt[i] += cnt_e / 2;
cnt_e = 0;
}
pre = e;
}
cnt[i] += cnt_e / 2;
}
ll ans = modm[0].size() / 2;
DEBUG(modm);
for(ll mod = 1; mod < M / 2 + (M & 1); mod++) {
ll i = mod, j = M - mod;
if(modm[i].size() < modm[j].size()) swap(i, j);
ans += modm[j].size();
ll diff = modm[i].size() - modm[j].size();
ans += min(cnt[i], diff / 2);
DEBUG(ans);
}
if(M % 2 == 0) ans += modm[M / 2].size() / 2;
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Pair Cards |
User |
kcvlex |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2754 Byte |
Status |
WA |
Exec Time |
21 ms |
Memory |
6528 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, sample-01.txt, sample-02.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
3 ms |
256 KB |
01-02.txt |
AC |
17 ms |
1400 KB |
01-03.txt |
AC |
17 ms |
1124 KB |
01-04.txt |
AC |
17 ms |
1468 KB |
01-05.txt |
AC |
17 ms |
1276 KB |
01-06.txt |
AC |
16 ms |
1536 KB |
01-07.txt |
AC |
15 ms |
1152 KB |
01-08.txt |
WA |
15 ms |
1536 KB |
01-09.txt |
WA |
15 ms |
1536 KB |
01-10.txt |
WA |
20 ms |
3200 KB |
01-11.txt |
WA |
20 ms |
5504 KB |
01-12.txt |
AC |
12 ms |
1400 KB |
01-13.txt |
WA |
13 ms |
2808 KB |
01-14.txt |
AC |
17 ms |
1124 KB |
01-15.txt |
AC |
16 ms |
1268 KB |
01-16.txt |
AC |
15 ms |
1664 KB |
01-17.txt |
AC |
14 ms |
1408 KB |
01-18.txt |
AC |
16 ms |
2048 KB |
01-19.txt |
AC |
17 ms |
1920 KB |
01-20.txt |
AC |
21 ms |
6528 KB |
01-21.txt |
AC |
16 ms |
1228 KB |
01-22.txt |
AC |
15 ms |
1408 KB |
01-23.txt |
AC |
14 ms |
1408 KB |
01-24.txt |
WA |
13 ms |
1536 KB |
01-25.txt |
WA |
15 ms |
2560 KB |
01-26.txt |
WA |
17 ms |
4736 KB |
01-27.txt |
AC |
11 ms |
4992 KB |
01-28.txt |
WA |
4 ms |
3456 KB |
01-29.txt |
AC |
2 ms |
1536 KB |
01-30.txt |
AC |
3 ms |
3328 KB |
sample-01.txt |
AC |
1 ms |
256 KB |
sample-02.txt |
AC |
1 ms |
256 KB |