Submission #6632975
Source Code Expand
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
signed main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
int N,M;
cin >> N >> M;
vector<int> X(N);
cin >> X;
map<int,int> cnt;
map<int, vector<int>> mp;
for (int x : X) cnt[x]++;
for (auto p : cnt) mp[p.first % M].push_back(p.second);
for (auto&& p : mp) { SORT(p.second); REV(p.second); }
int ans = 0;
for (int i = 0; 2 * i <= M; i++) {
if (i == 0 || 2 * i == M) {
ans += accumulate(ALL(mp[i]), 0LL) / 2;
} else {
vector<int> &a = mp[i], &b = mp[M - i];
int suma = accumulate(ALL(a), 0LL);
int sumb = accumulate(ALL(b), 0LL);
if (suma < sumb) {
swap(suma, sumb);
swap(a, b);
}
int rem = suma;
for (int i = 0; i < a.size(); i++) {
while (a[i] - 2 >= 0 && rem - 2 >= sumb) {
a[i] -= 2;
rem -= 2;
ans++;
}
}
ans += sumb;
}
}
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Pair Cards |
User |
legosuke |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
3302 Byte |
Status |
AC |
Exec Time |
101 ms |
Memory |
18176 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 |
1 ms |
256 KB |
01-02.txt |
AC |
39 ms |
5628 KB |
01-03.txt |
AC |
39 ms |
5584 KB |
01-04.txt |
AC |
40 ms |
5632 KB |
01-05.txt |
AC |
40 ms |
5632 KB |
01-06.txt |
AC |
40 ms |
5760 KB |
01-07.txt |
AC |
41 ms |
5760 KB |
01-08.txt |
AC |
43 ms |
5760 KB |
01-09.txt |
AC |
45 ms |
6016 KB |
01-10.txt |
AC |
60 ms |
9472 KB |
01-11.txt |
AC |
79 ms |
14848 KB |
01-12.txt |
AC |
9 ms |
1024 KB |
01-13.txt |
AC |
18 ms |
4480 KB |
01-14.txt |
AC |
51 ms |
8316 KB |
01-15.txt |
AC |
51 ms |
8320 KB |
01-16.txt |
AC |
53 ms |
8576 KB |
01-17.txt |
AC |
59 ms |
8320 KB |
01-18.txt |
AC |
58 ms |
9088 KB |
01-19.txt |
AC |
63 ms |
9728 KB |
01-20.txt |
AC |
101 ms |
18176 KB |
01-21.txt |
AC |
18 ms |
1280 KB |
01-22.txt |
AC |
18 ms |
1408 KB |
01-23.txt |
AC |
18 ms |
1408 KB |
01-24.txt |
AC |
19 ms |
1408 KB |
01-25.txt |
AC |
23 ms |
3712 KB |
01-26.txt |
AC |
36 ms |
9216 KB |
01-27.txt |
AC |
51 ms |
13184 KB |
01-28.txt |
AC |
20 ms |
8448 KB |
01-29.txt |
AC |
8 ms |
3456 KB |
01-30.txt |
AC |
22 ms |
8064 KB |
sample-01.txt |
AC |
1 ms |
256 KB |
sample-02.txt |
AC |
1 ms |
256 KB |