Submission #992889
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define fst(t) std::get<0>(t) #define snd(t) std::get<1>(t) #define thd(t) std::get<2>(t) using ll = long long; using P = std::tuple<int,int>; const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1}; int cnt[100100]; vector<int> v[100000]; int main(){ std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int N, M; std::cin >> N >> M; for(int i=0;i<N;++i){ int X; std::cin >> X; ++cnt[X]; } for(int i=1;i<=100000;++i){ for(int j=0;j<(cnt[i]&1);++j){ v[i % M].emplace_back(i); } } for(int i=1;i<=100000;++i){ for(int j=0;j<cnt[i]-(cnt[i]&1);++j){ v[i % M].emplace_back(i); } } int res = 0; for(int i=0;i<M;++i){ int i2 = (M - i) % M, v_size = v[i].size(); if(i2 < i){break;} if(i == i2){ for(int j=0;j<v_size-(v_size&1);j+=2){ ++res; --cnt[v[i][j]]; --cnt[v[i][j+1]]; // std::cout << "double: " << v[i][j] << ", " << v[i][j+1] << std::endl; } }else{ int mn = min(v[i].size(), v[i2].size()); for(int j=0;j<mn;++j){ ++res; --cnt[v[i][j]]; --cnt[v[i2][j]]; // std::cout << "single: " << v[i][j] << ", " << v[i2][j] << std::endl; } } } for(int i=1;i<=100000;++i){ res += cnt[i] / 2; } std::cout << res << std::endl; }
Submission Info
Submission Time | |
---|---|
Task | D - Pair Cards |
User | iwashisnake |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 1656 Byte |
Status | AC |
Exec Time | 22 ms |
Memory | 6144 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 | 6 ms | 2560 KB |
01-02.txt | AC | 16 ms | 3580 KB |
01-03.txt | AC | 16 ms | 3584 KB |
01-04.txt | AC | 16 ms | 3704 KB |
01-05.txt | AC | 16 ms | 3584 KB |
01-06.txt | AC | 16 ms | 3712 KB |
01-07.txt | AC | 16 ms | 3456 KB |
01-08.txt | AC | 17 ms | 3584 KB |
01-09.txt | AC | 17 ms | 3584 KB |
01-10.txt | AC | 21 ms | 4224 KB |
01-11.txt | AC | 22 ms | 4992 KB |
01-12.txt | AC | 15 ms | 3196 KB |
01-13.txt | AC | 15 ms | 3196 KB |
01-14.txt | AC | 15 ms | 3580 KB |
01-15.txt | AC | 16 ms | 3656 KB |
01-16.txt | AC | 16 ms | 3712 KB |
01-17.txt | AC | 16 ms | 3456 KB |
01-18.txt | AC | 17 ms | 3840 KB |
01-19.txt | AC | 18 ms | 3712 KB |
01-20.txt | AC | 22 ms | 6144 KB |
01-21.txt | AC | 16 ms | 3488 KB |
01-22.txt | AC | 16 ms | 3584 KB |
01-23.txt | AC | 16 ms | 3712 KB |
01-24.txt | AC | 16 ms | 3584 KB |
01-25.txt | AC | 17 ms | 3584 KB |
01-26.txt | AC | 17 ms | 3584 KB |
01-27.txt | AC | 14 ms | 4352 KB |
01-28.txt | AC | 7 ms | 3072 KB |
01-29.txt | AC | 6 ms | 3072 KB |
01-30.txt | AC | 6 ms | 2688 KB |
sample-01.txt | AC | 6 ms | 2560 KB |
sample-02.txt | AC | 6 ms | 2560 KB |