Submission #993289
Source Code Expand
#include <vector> #include <list> #include <map> #include <set> #include <deque> #include <stack> #include <queue> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> using namespace std; typedef long long ll; typedef unsigned long long ull; static const double EPS = 1e-8; static const double PI = 4.0 * atan(1.0); static const double PI2 = 8.0 * atan(1.0); #define REP(i,n) for(int i=0;i<(int)n;++i) #define ALL(c) (c).begin(),(c).end() #define CLEAR(v) memset(v,0,sizeof(v)) #define MP(a,b) make_pair((a),(b)) #define ABS(a) ((a)>0?(a):-(a)) #define FOR(i,s,n) for(int i=s;i<(int)n;++i) int N, M; int X[100000]; vector<int> md[100000]; vector<pair<int, int>> md2[100000]; int main(int argc, char **argv) { cin >> N >> M; REP(i, N) { cin >> X[i]; md[X[i] % M].push_back(X[i]); } REP(i, M) { sort(ALL(md[i])); int p = -1, cnt = 0; REP(j, md[i].size()) { if (md[i][j] != p) { if (cnt != 0) { md2[i].push_back(MP(p, cnt)); } p = md[i][j]; cnt = 0; } ++cnt; } if (cnt != 0) md2[i].push_back(MP(md[i][md[i].size() - 1], cnt)); } int res = md[0].size() / 2; FOR(i, 1, (M - 1) / 2 + 1) { int a = 0, b = 0; while (true) { while (a < md2[i].size() && md2[i][a].second % 2 == 0) ++a; while (b < md2[M - i].size() && md2[M - i][b].second % 2 == 0) ++b; if (a >= md2[i].size()) { int k = 0; while (b < md2[M - i].size()) { while (k < md2[i].size() && md2[i][k].second == 0) ++k; if (k == md2[i].size()) break; --md2[i][k].second; --md2[M - i][b].second; ++res; while (b < md2[M - i].size() && md2[M - i][b].second % 2 == 0) ++b; } break; } if (b >= md2[M - i].size()) { int k = 0; while (a < md2[i].size()) { while (k < md2[M - i].size() && md2[M - i][k].second == 0) ++k; if (k == md2[M - i].size()) break; --md2[i][a].second; --md2[M - i][k].second; ++res; while (a < md2[i].size() && md2[i][a].second % 2 == 0) ++a; } break; } --md2[i][a].second; --md2[M - i][b].second; ++res; } REP(j, md2[i].size()) res += md2[i][j].second / 2; REP(j, md2[M - i].size()) res += md2[M - i][j].second / 2; } if (M % 2 == 0) { int a = 0, b = 0; while (true) { while (a < md2[M / 2].size() && md2[M / 2][a].second % 2 == 0) ++a; b = a + 1; while (b < md2[M / 2].size() && md2[M / 2][b].second % 2 == 0) ++b; if (b >= md2[M / 2].size()) break; --md2[M / 2][a].second; --md2[M / 2][b].second; ++res; } REP(j, md2[M / 2].size()) res += md2[M / 2][j].second / 2; } cout << res << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Pair Cards |
User | yupotown |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 2921 Byte |
Status | AC |
Exec Time | 58 ms |
Memory | 11520 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 | 7 ms | 4992 KB |
01-02.txt | AC | 48 ms | 6520 KB |
01-03.txt | AC | 47 ms | 6396 KB |
01-04.txt | AC | 48 ms | 6520 KB |
01-05.txt | AC | 48 ms | 6400 KB |
01-06.txt | AC | 46 ms | 6528 KB |
01-07.txt | AC | 46 ms | 6400 KB |
01-08.txt | AC | 46 ms | 6528 KB |
01-09.txt | AC | 47 ms | 6656 KB |
01-10.txt | AC | 54 ms | 7680 KB |
01-11.txt | AC | 55 ms | 9216 KB |
01-12.txt | AC | 42 ms | 5884 KB |
01-13.txt | AC | 43 ms | 5884 KB |
01-14.txt | AC | 48 ms | 6924 KB |
01-15.txt | AC | 47 ms | 6876 KB |
01-16.txt | AC | 47 ms | 7040 KB |
01-17.txt | AC | 46 ms | 6784 KB |
01-18.txt | AC | 49 ms | 7680 KB |
01-19.txt | AC | 50 ms | 7040 KB |
01-20.txt | AC | 58 ms | 11520 KB |
01-21.txt | AC | 45 ms | 5824 KB |
01-22.txt | AC | 44 ms | 5760 KB |
01-23.txt | AC | 44 ms | 5888 KB |
01-24.txt | AC | 43 ms | 5888 KB |
01-25.txt | AC | 44 ms | 6144 KB |
01-26.txt | AC | 44 ms | 6144 KB |
01-27.txt | AC | 32 ms | 8192 KB |
01-28.txt | AC | 9 ms | 5120 KB |
01-29.txt | AC | 7 ms | 4992 KB |
01-30.txt | AC | 7 ms | 4992 KB |
sample-01.txt | AC | 7 ms | 4992 KB |
sample-02.txt | AC | 7 ms | 4992 KB |