Submission #7505854
Source Code Expand
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;
#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl
constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template<typename T>
bool chmax(T& a, T b, bool equal = false){
if(a < b || equal && a == b){
a = b;
return true;
}
return false;
}
template<typename T>
bool chmin(T& a, T b, bool equal = false){
if(b < a || equal && a == b){
a = b;
return true;
}
return false;
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> x(n);
map<int, int> cnt;
rep(i, m + 1){
cnt[i] = 0;
}
rep(i, n){
cin >> x[i];
++cnt[x[i] % m];
}
map<int, int> mp;
rep(i, n - 1){
int p = x[i] % m;
if(p == 0){
continue;
}else if(x[i] == x[i + 1]){
++mp[p];
++i;
}
}
int ans = 0;
for(auto x : cnt){
if(x.first > m / 2){
break;
}
if(x.first == 0 || (m % 2 == 0 && x.first == m / 2)){
ans += x.second / 2;
}else{
auto it = cnt.lower_bound(m - x.first);
ans += min(x.second, (*it).second);
int tmp;
if(x.second < (*it).second){
tmp = (*it).second - x.second;
ans += min(tmp / 2, mp[(*it).first]);
}else if(x.second > (*it).second){
tmp = x.second - (*it).second;
ans += min(tmp / 2, mp[x.first]);
}
}
}
cout << ans << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Pair Cards |
User |
mhrb |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2724 Byte |
Status |
WA |
Exec Time |
77 ms |
Memory |
7552 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, sample-01.txt, sample-02.txt |
Case Name |
Status |
Exec Time |
Memory |
01-01.txt |
AC |
1 ms |
256 KB |
01-02.txt |
AC |
10 ms |
640 KB |
01-03.txt |
AC |
11 ms |
640 KB |
01-04.txt |
WA |
11 ms |
640 KB |
01-05.txt |
WA |
11 ms |
640 KB |
01-06.txt |
WA |
11 ms |
640 KB |
01-07.txt |
WA |
12 ms |
640 KB |
01-08.txt |
WA |
15 ms |
640 KB |
01-09.txt |
WA |
17 ms |
768 KB |
01-10.txt |
WA |
45 ms |
3328 KB |
01-11.txt |
WA |
77 ms |
6912 KB |
01-12.txt |
AC |
10 ms |
640 KB |
01-13.txt |
AC |
21 ms |
2688 KB |
01-14.txt |
AC |
11 ms |
640 KB |
01-15.txt |
AC |
11 ms |
640 KB |
01-16.txt |
AC |
12 ms |
640 KB |
01-17.txt |
AC |
14 ms |
640 KB |
01-18.txt |
AC |
18 ms |
768 KB |
01-19.txt |
AC |
26 ms |
1280 KB |
01-20.txt |
AC |
71 ms |
5376 KB |
01-21.txt |
AC |
11 ms |
640 KB |
01-22.txt |
WA |
11 ms |
640 KB |
01-23.txt |
WA |
12 ms |
640 KB |
01-24.txt |
WA |
16 ms |
768 KB |
01-25.txt |
WA |
36 ms |
2304 KB |
01-26.txt |
WA |
70 ms |
5504 KB |
01-27.txt |
AC |
58 ms |
7552 KB |
01-28.txt |
WA |
33 ms |
5120 KB |
01-29.txt |
AC |
10 ms |
2176 KB |
01-30.txt |
AC |
31 ms |
4992 KB |
sample-01.txt |
AC |
1 ms |
256 KB |
sample-02.txt |
AC |
1 ms |
256 KB |