Submission #7507473
Source Code Expand
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++)
#define rep(i, begin, end) for(int i = int(begin); i < int(end); i++)
#define all(v) v.begin(), v.end()
#define lint long long
auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;};
auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;};
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail){
std::cerr << " " << head;
debug_impl(tail...);
}
#define debug(...)\
std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
debug_impl(__VA_ARGS__);\
std::cerr << std::noboolalpha;
template <typename T>
std::istream& operator>> (std::istream& is, std::vector<T>& v) {
for (auto & x : v) is >> x;
return is;
}
template <typename T>
std::ostream& operator<< (std::ostream& os, const std::vector<T>& v) {
auto n = v.size();
os << "{";
for (size_t i = 0; i < n; i++)
{os << (i > 0 ? "," : "") << v.at(i);}
return os << "}";
}
template <typename T, typename U>
std::ostream& operator<< (std::ostream& os, const std::pair<T, U>& pair)
{ return os << "(" << pair.first << "," << pair.second << ")"; }
template <typename T, typename U>
std::istream& operator>> (std::iostream& is, std::pair<T, U>& pair)
{ return is >> pair.first >> pair.second; }
template <typename T>
auto make_vector_impl(size_t sz, T t) {return std::vector<T>(sz, t);}
template <size_t N, typename T, typename U, std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz, U u) {return make_vector_impl(sz, T(u));}
template <size_t N, typename T, std::enable_if_t<N == 1, std::nullptr_t> = nullptr>
auto make_vector(size_t sz) {return std::vector<T>(sz);}
template <size_t N, typename T, typename... Args, std::enable_if_t<N != 1, std::nullptr_t> = nullptr>
auto make_vector(size_t a, Args... args) {return make_vector_impl(a, make_vector<N - 1, T>(args...));}
template <typename T, typename Size_t>
auto& at(T& t, Size_t i) {return t.at(i);}
template <typename T, typename Size_t, typename... Args>
auto& at(T& t, Size_t i, Args... args) {return at(t.at(i), args...);}
int main() {
std::cin.tie(0); std::cin.sync_with_stdio(false);
int n, m; std::cin >> n >> m;
auto a = make_vector< 2, int >(m, 0);
loop(n){
int x; std::cin >> x;
a.at(x % m).emplace_back(x);
}
for(auto & v : a) std::sort(all(v));
auto b = std::vector< std::pair< int, int >>(m); // cnt, pairing
rep(i, 0, m) {
auto prv = -1, now = 0, pairing = 0;
for (auto crr : a.at(i)) {
if (prv != crr && prv != -1) {
pairing += now / 2;
now = 0;
}
now++;
prv = crr;
}
pairing += now / 2;
b.at(i) = { a.at(i).size(), pairing };
}
auto cal = [&] (auto&& p, auto&& q) {
int a, b, c, d;
std::tie(a, b) = p;
std::tie(c, d) = q;
if (a > c) {
std::swap(a, c);
std::swap(b, d);
}
return a + std::min(c - a, d);
};
auto dal = [&] (auto&& p)
{ return p.first / 2; };
auto ret = 0LL;
rep(i, 0, m) {
auto j = m - i;
if (i > j) break;
else if (i == 0 || i == j) ret += dal(b.at(i));
else ret += cal(b.at(i), b.at(j));
}
// debug(b);
std::cout << ret << std::endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
D - Pair Cards |
User |
ngtkana |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
3456 Byte |
Status |
WA |
Exec Time |
21 ms |
Memory |
6528 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 |
16 ms |
892 KB |
01-03.txt |
AC |
16 ms |
892 KB |
01-04.txt |
WA |
16 ms |
896 KB |
01-05.txt |
WA |
16 ms |
768 KB |
01-06.txt |
WA |
15 ms |
896 KB |
01-07.txt |
WA |
15 ms |
768 KB |
01-08.txt |
WA |
14 ms |
896 KB |
01-09.txt |
WA |
14 ms |
896 KB |
01-10.txt |
WA |
19 ms |
2688 KB |
01-11.txt |
WA |
21 ms |
5376 KB |
01-12.txt |
AC |
11 ms |
892 KB |
01-13.txt |
AC |
12 ms |
2168 KB |
01-14.txt |
AC |
16 ms |
788 KB |
01-15.txt |
AC |
15 ms |
896 KB |
01-16.txt |
AC |
14 ms |
1024 KB |
01-17.txt |
AC |
13 ms |
768 KB |
01-18.txt |
AC |
14 ms |
1280 KB |
01-19.txt |
AC |
16 ms |
1408 KB |
01-20.txt |
AC |
19 ms |
6528 KB |
01-21.txt |
AC |
15 ms |
896 KB |
01-22.txt |
WA |
14 ms |
768 KB |
01-23.txt |
WA |
13 ms |
896 KB |
01-24.txt |
WA |
12 ms |
896 KB |
01-25.txt |
WA |
14 ms |
1920 KB |
01-26.txt |
WA |
16 ms |
4096 KB |
01-27.txt |
AC |
11 ms |
4992 KB |
01-28.txt |
WA |
4 ms |
3456 KB |
01-29.txt |
AC |
2 ms |
1536 KB |
01-30.txt |
AC |
3 ms |
3328 KB |
sample-01.txt |
AC |
1 ms |
256 KB |
sample-02.txt |
AC |
1 ms |
256 KB |