Submission #994691
Source Code Expand
#include<iostream> #include<map> #include<vector> int main(){ int n,m; std::cin >> n >> m; std::vector<int> x(n); std::map<int,std::map<int,int> > units; std::map<int,std::map<int,int> > buf; for(int i=0;i<n;i++){ std::cin >> x[i]; if(buf[x[i]%m].find(x[i])==buf[x[i]%m].end()){ if(units[x[i]%m].find(x[i])!=units[x[i]%m].end()){ buf[x[i]%m][x[i]] = 2; units[x[i]%m].erase(x[i]); }else{ units[x[i]%m][x[i]] = 1; } }else{ buf[x[i]%m][x[i]]++; } } /*for(int i=0;i<m;i++){ std::cout << "[" << i << "]"; auto u = buf[i]; for(auto it=u.begin();it!=u.end();it++){ std::cout << "(" << it->first << "," << it->second << ")"; } std::cout << std::endl; }*/ int count = 0; for(int i=0;i<m;i++){ if(units.find(i)==units.end())continue; auto &u = units[i]; if(i==0 || i*2==m){ count += u.size()/2; if(u.size()%2==1){ buf[i][0]++; } }else if(units.find(m-i)!=units.end()){ auto &v = units[m-i]; count += std::min(u.size(),v.size()); if(u.size() > v.size()){ buf[i][0]+=u.size()-v.size(); }else if(u.size() < v.size()){ buf[m-i][0]+=v.size()-u.size(); } units.erase(i); units.erase(m-i); }else{ buf[i][0]+=u.size(); } } /*std::cout << count << std::endl; for(int i=0;i<m;i++){ std::cout << "[" << i << "]"; auto u = buf[i]; for(auto it=u.begin();it!=u.end();it++){ std::cout << "(" << it->first << "," << it->second << ")"; } std::cout << std::endl; }*/ while(1){ bool update = false; for(auto pt=buf.begin();pt!=buf.end();pt++){ int i = pt->first; auto &u = pt->second; if(i==0 || i*2==m){ for(auto it=u.begin();it!=u.end();it++){ if(it->second%2==1 || it->first==0){ bool po = false; for(auto jt=it;jt!=u.end();jt++){ break; if(it!=jt && (jt->second%2==1 || jt->first==0)){ it->second--; jt->second--; count++; update = po = true; if(jt->second==0){ u.erase(jt); } break; } } if(!po){ for(auto jt=u.begin();jt!=u.end();jt++){ if(it==jt)continue; it->second--; jt->second--; count++; update = po = true; if(jt->second==0){ u.erase(jt); } break; } } if(po){ if(it->second==0){ it = u.erase(it); if(it==u.end())break; else it--; } } } } }else{ int j = m-i; if(buf.find(j)==buf.end())continue; auto &v = buf[j]; for(auto it=u.begin();it!=u.end();it++){ if(it->second%2==1 || it->first==0){ bool po = false; for(auto jt=v.begin();jt!=v.end();jt++){ break; if(jt->second%2==1 || jt->first==0){ it->second--; jt->second--; count++; update = po = true; if(jt->second==0){ v.erase(jt); } break; } } if(!po){ for(auto jt=v.begin();jt!=v.end();jt++){ it->second--; jt->second--; count++; update = po = true; if(jt->second==0){ v.erase(jt); } break; } } if(po){ if(it->second==0){ it = u.erase(it); if(it==u.end())break; else it--; } } } } } if(u.size()==0){ pt = buf.erase(pt); if(pt==buf.end())break; else pt--; } } if(!update)break; } for(auto pt=buf.begin();pt!=buf.end();pt++){ int i = pt->first; auto &u = pt->second; for(auto it=u.begin();it!=u.end();it++){ if(it->first!=0)count += it->second/2; } } std::cout << count << std::endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Pair Cards |
User | phi16 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 4562 Byte |
Status | WA |
Exec Time | 1064 ms |
Memory | 24064 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 |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01-01.txt | AC | 2 ms | 256 KB |
01-02.txt | AC | 92 ms | 3584 KB |
01-03.txt | AC | 94 ms | 3584 KB |
01-04.txt | AC | 92 ms | 3584 KB |
01-05.txt | AC | 1064 ms | 3584 KB |
01-06.txt | AC | 1016 ms | 3584 KB |
01-07.txt | AC | 523 ms | 3584 KB |
01-08.txt | AC | 123 ms | 3712 KB |
01-09.txt | AC | 116 ms | 3968 KB |
01-10.txt | WA | 150 ms | 10368 KB |
01-11.txt | AC | 186 ms | 15488 KB |
01-12.txt | AC | 32 ms | 640 KB |
01-13.txt | AC | 32 ms | 640 KB |
01-14.txt | AC | 77 ms | 5376 KB |
01-15.txt | AC | 77 ms | 5376 KB |
01-16.txt | AC | 77 ms | 5376 KB |
01-17.txt | AC | 94 ms | 5376 KB |
01-18.txt | AC | 103 ms | 5888 KB |
01-19.txt | AC | 114 ms | 7680 KB |
01-20.txt | AC | 179 ms | 24064 KB |
01-21.txt | AC | 243 ms | 768 KB |
01-22.txt | AC | 211 ms | 768 KB |
01-23.txt | AC | 75 ms | 768 KB |
01-24.txt | AC | 68 ms | 1024 KB |
01-25.txt | AC | 67 ms | 1664 KB |
01-26.txt | AC | 68 ms | 1664 KB |
01-27.txt | AC | 95 ms | 14464 KB |
01-28.txt | AC | 9 ms | 1152 KB |
01-29.txt | AC | 3 ms | 384 KB |
01-30.txt | AC | 3 ms | 256 KB |
sample-01.txt | AC | 2 ms | 256 KB |
sample-02.txt | AC | 2 ms | 256 KB |