Submission #7939252
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i)) #define REP(i, n) FOR(i, n, 0) #define OF64 std::setprecision(10) const ll MOD = 1000000007; const ll INF = (ll)1e15; vector<ll> Y[100005]; //! 同じmodのなかで同じ整数ペアの数 ll P[100005]; ll S[100005]; int main() { ll N, M; cin >> N >> M; vector<ll> v; REP(i, N) { ll x; cin >> x; Y[x % M].push_back(x); if (Y[x % M].size() == 1) v.push_back(x % M); } memset(P, 0, sizeof(P)); memset(S, 0, sizeof(S)); REP(i, v.size()) { sort(Y[v[i]].begin(), Y[v[i]].end()); ll p = 0; FOR(j, Y[v[i]].size(), 1) { if (Y[v[i]][j - 1] == Y[v[i]][j]) { p++; j++; } } S[v[i]] = Y[v[i]].size(); P[v[i]] = p; } ll ans = 0; REP(i, v.size()) { //! 先に足してMの倍数になるのかぞえる ll n = std::min(S[v[i]], S[(M - v[i]) % M]); if (v[i] == 0 || v[i] == M / 2) n /= 2; ans += n; S[v[i]] -= n; S[(M - v[i]) % M] -= n; } REP(i, v.size()) { //! ペアが残ってれば数える ans += std::min(P[v[i]], S[v[i]] / 2); } cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Pair Cards |
User | coco18000 |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 1510 Byte |
Status | AC |
Exec Time | 45 ms |
Memory | 8052 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 | 3 ms | 4096 KB |
01-02.txt | AC | 39 ms | 5108 KB |
01-03.txt | AC | 38 ms | 5084 KB |
01-04.txt | AC | 38 ms | 5040 KB |
01-05.txt | AC | 38 ms | 5056 KB |
01-06.txt | AC | 38 ms | 5344 KB |
01-07.txt | AC | 37 ms | 5120 KB |
01-08.txt | AC | 36 ms | 5376 KB |
01-09.txt | AC | 36 ms | 5376 KB |
01-10.txt | AC | 42 ms | 6136 KB |
01-11.txt | AC | 45 ms | 6776 KB |
01-12.txt | AC | 35 ms | 5108 KB |
01-13.txt | AC | 35 ms | 5108 KB |
01-14.txt | AC | 39 ms | 5084 KB |
01-15.txt | AC | 38 ms | 5232 KB |
01-16.txt | AC | 37 ms | 5632 KB |
01-17.txt | AC | 36 ms | 5248 KB |
01-18.txt | AC | 37 ms | 5888 KB |
01-19.txt | AC | 39 ms | 5504 KB |
01-20.txt | AC | 45 ms | 8052 KB |
01-21.txt | AC | 37 ms | 5064 KB |
01-22.txt | AC | 36 ms | 5208 KB |
01-23.txt | AC | 35 ms | 5376 KB |
01-24.txt | AC | 34 ms | 5376 KB |
01-25.txt | AC | 36 ms | 5504 KB |
01-26.txt | AC | 36 ms | 5504 KB |
01-27.txt | AC | 23 ms | 6136 KB |
01-28.txt | AC | 4 ms | 4224 KB |
01-29.txt | AC | 3 ms | 4224 KB |
01-30.txt | AC | 2 ms | 4096 KB |
sample-01.txt | AC | 2 ms | 4096 KB |
sample-02.txt | AC | 2 ms | 4096 KB |