Submission #1799790
Source Code Expand
#include<cstdio> #include<cstdlib> #include<cmath> #include<iostream> #include<string> #include<stack> #include<queue> #include<vector> #include<map> #include<set> #include<algorithm> #include<numeric> #define rep(n) for(int i=0;i<n;i++) #define repp(j, n) for(int j=0;j<n;j++) #define reppp(i, m, n) for(int i=m;i<=n;i++) #define all(c) c.begin(), c.end() #define rall(c) c.rbegin(), c.rend() #define MOD 1000000007 #define MAX 1000000001 #define INF 1410065408 #define EPS 1e-9 #define DEBUG 0 #define ll long long #define Pll pair<ll, ll> #define Pii pair<int, int> using namespace std; struct edge{int from, to; ll cost;}; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n,m; cin >> n >> m; map<int, int> cards[m]; vector<int> counts(m, 0); rep(n){ int tmp; cin >> tmp; cards[tmp%m][tmp]++; counts[tmp%m]++; } int ans = counts[0] / 2; reppp(i, 1, (m-1)/2){ if(counts[i] < counts[m-i]){ swap(counts[i], counts[m-i]); swap(cards[i], cards[m-i]); } int diff = counts[i] - counts[m-i]; if(diff >= 2){ for(auto itr=cards[i].begin(); itr!=cards[i].end(); ++itr){ if(itr->second >= 2){ int tmp = min(diff, itr->second)/2; ans += tmp; counts[i] -= tmp*2; diff = counts[i] - counts[m-i]; if(diff == 0) break; } } } ans += min(counts[i], counts[m-i]); //cout << i << " " << ans << endl; } if(m % 2 == 0){ ans += counts[m/2]/2; } cout << ans; }
Submission Info
Submission Time | |
---|---|
Task | D - Pair Cards |
User | Noimin |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 1750 Byte |
Status | AC |
Exec Time | 43 ms |
Memory | 9984 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 | 37 ms | 3200 KB |
01-03.txt | AC | 36 ms | 3200 KB |
01-04.txt | AC | 37 ms | 3200 KB |
01-05.txt | AC | 36 ms | 3200 KB |
01-06.txt | AC | 35 ms | 3200 KB |
01-07.txt | AC | 35 ms | 3200 KB |
01-08.txt | AC | 31 ms | 3200 KB |
01-09.txt | AC | 28 ms | 3328 KB |
01-10.txt | AC | 22 ms | 5248 KB |
01-11.txt | AC | 21 ms | 8320 KB |
01-12.txt | AC | 10 ms | 256 KB |
01-13.txt | AC | 11 ms | 2432 KB |
01-14.txt | AC | 43 ms | 4992 KB |
01-15.txt | AC | 42 ms | 4992 KB |
01-16.txt | AC | 41 ms | 4992 KB |
01-17.txt | AC | 37 ms | 4992 KB |
01-18.txt | AC | 33 ms | 5120 KB |
01-19.txt | AC | 27 ms | 5632 KB |
01-20.txt | AC | 23 ms | 9984 KB |
01-21.txt | AC | 19 ms | 384 KB |
01-22.txt | AC | 18 ms | 384 KB |
01-23.txt | AC | 16 ms | 512 KB |
01-24.txt | AC | 13 ms | 512 KB |
01-25.txt | AC | 13 ms | 2048 KB |
01-26.txt | AC | 15 ms | 5504 KB |
01-27.txt | AC | 13 ms | 7680 KB |
01-28.txt | AC | 4 ms | 5504 KB |
01-29.txt | AC | 3 ms | 2304 KB |
01-30.txt | AC | 4 ms | 5376 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |