Submission #5430972
Source Code Expand
#include <bits/stdc++.h> using namespace std; //repetition #define FOR(i,a,b) for(ll i=(a);i<(b);++i) #define rep(i, n) for(ll i = 0; i < (ll)(n); i++) //container util #define all(x) (x).begin(),(x).end() //typedef typedef long long ll; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VLL; typedef vector<VLL> VVLL; typedef vector<string> VS; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; //conversion inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} int main(){ ios::sync_with_stdio(false); cin.tie(0); int n,m; cin >> n >> m; map<int,int> mp; VI x(n); map<int,int> tmp; map<int,int> pairCnt; rep(i,n){ cin >> x[i]; if(tmp[x[i]] > 0){ tmp[x[i]]--; pairCnt[x[i]%m]++; }else { tmp[x[i]]++; } mp[x[i] % m]++; } ll ans = 0; rep(i,m){ int x; if(i != (m-i)%m) x = min(mp[i] , mp[(m-i)%m]); else x = mp[i]/2; mp[i] -= x; mp[(m-i)%m] -= x; ans += x; } //cout << "ans" << ' ' << ans << "\n"; rep(i,m){ //cout << i << ':' << pairCnt[i] << "\n"; if(pairCnt[i] > 0 && mp[i] > 0){ ans += min(mp[i]/2,pairCnt[i]); } } cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Pair Cards |
User | edamame88 |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 1524 Byte |
Status | AC |
Exec Time | 140 ms |
Memory | 14720 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 | 45 ms | 3584 KB |
01-03.txt | AC | 46 ms | 3584 KB |
01-04.txt | AC | 48 ms | 3584 KB |
01-05.txt | AC | 46 ms | 3584 KB |
01-06.txt | AC | 48 ms | 3584 KB |
01-07.txt | AC | 48 ms | 3584 KB |
01-08.txt | AC | 56 ms | 3712 KB |
01-09.txt | AC | 63 ms | 3840 KB |
01-10.txt | AC | 103 ms | 7424 KB |
01-11.txt | AC | 140 ms | 13056 KB |
01-12.txt | AC | 10 ms | 640 KB |
01-13.txt | AC | 37 ms | 4736 KB |
01-14.txt | AC | 52 ms | 5504 KB |
01-15.txt | AC | 53 ms | 5376 KB |
01-16.txt | AC | 55 ms | 5376 KB |
01-17.txt | AC | 59 ms | 5376 KB |
01-18.txt | AC | 66 ms | 5632 KB |
01-19.txt | AC | 77 ms | 6528 KB |
01-20.txt | AC | 133 ms | 14720 KB |
01-21.txt | AC | 26 ms | 896 KB |
01-22.txt | AC | 27 ms | 896 KB |
01-23.txt | AC | 29 ms | 896 KB |
01-24.txt | AC | 39 ms | 896 KB |
01-25.txt | AC | 60 ms | 3712 KB |
01-26.txt | AC | 97 ms | 10240 KB |
01-27.txt | AC | 104 ms | 12160 KB |
01-28.txt | AC | 55 ms | 9856 KB |
01-29.txt | AC | 21 ms | 3968 KB |
01-30.txt | AC | 62 ms | 9600 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |