Submission #992433
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++) #define REP(i,n) FOR(i,0,n) #define ALL(a) a.begin(), a.end() #define MS(m,v) memset(m,v,sizeof(m)) typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<string> vs; typedef pair<int, int> pii; const int MOD = 1000000007; const int INF = MOD + 1; const ld EPS = 1e-12; template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); } template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); } /*--------------------template--------------------*/ int main() { cin.sync_with_stdio(false); cout << fixed << setprecision(10); int n, m; cin >> n >> m; vi x(n); REP(i, n) cin >> x[i]; sort(ALL(x)); vector<vi> v(m); for(auto i : x) { v[i % m].push_back(i); } vi p(m); REP(i, m) { REP(j, v[i].size() - 1) { if (v[i][j] == v[i][j + 1]) { p[i]++; j++; } } } int ans = 0; ans += v[0].size() / 2; if (m % 2 == 0) ans += v[m / 2].size() / 2; FOR(i, 1, (m+1) / 2) { int j = m - i; int a = v[i].size(), b = v[j].size(); if (a >= b) { ans += b; int np = a - 2 * p[i]; if (np >= b) ans += p[i]; else ans += (a - b) / 2; } else { ans += a; int np = b - 2 * p[j]; if (np >= a) ans += p[j]; else ans += (b - a) / 2; } } cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Pair Cards |
User | amano |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 1443 Byte |
Status | AC |
Exec Time | 28 ms |
Memory | 6528 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 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 2 ms | 256 KB |
01-02.txt | AC | 19 ms | 1276 KB |
01-03.txt | AC | 19 ms | 1232 KB |
01-04.txt | AC | 19 ms | 1280 KB |
01-05.txt | AC | 19 ms | 1280 KB |
01-06.txt | AC | 19 ms | 1280 KB |
01-07.txt | AC | 19 ms | 1152 KB |
01-08.txt | AC | 19 ms | 1280 KB |
01-09.txt | AC | 20 ms | 1280 KB |
01-10.txt | AC | 25 ms | 2944 KB |
01-11.txt | AC | 28 ms | 5376 KB |
01-12.txt | AC | 14 ms | 1276 KB |
01-13.txt | AC | 15 ms | 2300 KB |
01-14.txt | AC | 19 ms | 1276 KB |
01-15.txt | AC | 19 ms | 1352 KB |
01-16.txt | AC | 19 ms | 1408 KB |
01-17.txt | AC | 19 ms | 1152 KB |
01-18.txt | AC | 20 ms | 1536 KB |
01-19.txt | AC | 21 ms | 1664 KB |
01-20.txt | AC | 28 ms | 6528 KB |
01-21.txt | AC | 18 ms | 1232 KB |
01-22.txt | AC | 17 ms | 1152 KB |
01-23.txt | AC | 18 ms | 1280 KB |
01-24.txt | AC | 18 ms | 1280 KB |
01-25.txt | AC | 20 ms | 2176 KB |
01-26.txt | AC | 22 ms | 3968 KB |
01-27.txt | AC | 17 ms | 4736 KB |
01-28.txt | AC | 7 ms | 3072 KB |
01-29.txt | AC | 4 ms | 1408 KB |
01-30.txt | AC | 6 ms | 2944 KB |
sample-01.txt | AC | 2 ms | 256 KB |
sample-02.txt | AC | 3 ms | 256 KB |