Submission #993119
Source Code Expand
#include<iostream> #include<map> #include<vector> int main(){ int n,m; std::cin >> n >> m; std::vector<int> x(n); std::vector<std::map<int,int> > buf(m); for(int i=0;i<n;i++){ std::cin >> x[i]; 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; while(1){ bool update = false; for(int i=0;i<m;i++){ auto &u = buf[i]; if(i==0 || i*2==m){ for(auto it=u.begin();it!=u.end();it++){ if(it->second%2==1){ bool po = false; for(auto jt=u.begin();jt!=u.end();jt++){ if(it!=jt && jt->second%2==1){ 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; auto &v = buf[j]; for(auto it=u.begin();it!=u.end();it++){ if(it->second%2==1){ bool po = false; for(auto jt=v.begin();jt!=v.end();jt++){ if(jt->second%2==1){ 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(!update)break; } for(int i=0;i<m;i++){ auto &u = buf[i]; for(auto it=u.begin();it!=u.end();it++){ 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 | 3024 Byte |
Status | TLE |
Exec Time | 2102 ms |
Memory | 9984 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 | 3 ms | 256 KB |
01-02.txt | TLE | 2102 ms | 3584 KB |
01-03.txt | TLE | 2102 ms | 3584 KB |
01-04.txt | TLE | 2102 ms | 3584 KB |
01-05.txt | TLE | 2102 ms | 3584 KB |
01-06.txt | AC | 1747 ms | 3584 KB |
01-07.txt | AC | 775 ms | 3584 KB |
01-08.txt | AC | 85 ms | 3584 KB |
01-09.txt | AC | 64 ms | 3712 KB |
01-10.txt | AC | 50 ms | 5504 KB |
01-11.txt | AC | 53 ms | 8320 KB |
01-12.txt | AC | 31 ms | 640 KB |
01-13.txt | AC | 34 ms | 2688 KB |
01-14.txt | AC | 68 ms | 5376 KB |
01-15.txt | AC | 68 ms | 5376 KB |
01-16.txt | AC | 67 ms | 5376 KB |
01-17.txt | AC | 64 ms | 5376 KB |
01-18.txt | AC | 60 ms | 5504 KB |
01-19.txt | AC | 53 ms | 5888 KB |
01-20.txt | AC | 49 ms | 9984 KB |
01-21.txt | AC | 660 ms | 768 KB |
01-22.txt | AC | 264 ms | 768 KB |
01-23.txt | AC | 72 ms | 768 KB |
01-24.txt | AC | 38 ms | 896 KB |
01-25.txt | AC | 39 ms | 2176 KB |
01-26.txt | AC | 48 ms | 5504 KB |
01-27.txt | AC | 29 ms | 7424 KB |
01-28.txt | AC | 10 ms | 5120 KB |
01-29.txt | AC | 5 ms | 2176 KB |
01-30.txt | AC | 9 ms | 4864 KB |
sample-01.txt | AC | 3 ms | 256 KB |
sample-02.txt | AC | 3 ms | 256 KB |