Submission #992266
Source Code Expand
/* -------------------------------- Template -------------------------------- */ #include <algorithm> #include <array> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <locale> #include <iostream> #include <map> #include <memory> #include <new> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define REP(i,n) for(int i=0;i<(int)(n);i++) #define ALL(x) (x).begin(),(x).end() using ll = long long; using ld = long double; template <typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); } template<typename T> constexpr T inf = [](){ assert(false); }; // template<> constexpr int inf<int> = 1e9; // template<> constexpr ll inf<ll> = 1e18; // template<> constexpr ld inf<ld> = 1e30; struct yes_no : std::numpunct<char> { string_type do_truename() const { return "YES"; } string_type do_falsename() const { return "NO"; } }; void solve(); int main() { std::locale loc(std::locale(), new yes_no); std::cout << std::boolalpha << std::setprecision(12) << std::fixed; std::cout.imbue(loc); solve(); return 0; } using namespace std; /* -------------------------------- Library -------------------------------- */ /* ---------------------------------- Main ---------------------------------- */ void solve() { int N, M; cin >> N >> M; vector<vector<int>> vec(M); REP(i,N) { int X; cin >> X; vec[X % M].push_back(X); } REP(i,M) sort(ALL(vec[i])); vector<int> one(M), two(M); REP(i,M) { const int n = vec[i].size(); REP(j,n) { if (j < n - 1 && vec[i][j] == vec[i][j+1]) { ++j; ++two[i]; } else ++one[i]; } } int res = 0; REP(i,(M+2)/2) { if (i * 2 == M) { res += two[i] + one[i] / 2; } else if (i == 0) { res += two[i] + one[i] / 2; } else { const int a = min(one[i], one[M-i]); one[i] -= a; one[M-i] -= a; res += a; const int b = min(one[i], two[M-i] * 2); one[i] -= b; two[M-i] -= (b+1)/2; res += b; const int c = min(two[i] * 2, one[M-i]); two[i] -= (c+1)/2; one[M-i] -= c; res += c; res += two[i] + two[M-i]; } // cout << res << endl; } cout << res << endl; return; }
Submission Info
Submission Time | |
---|---|
Task | D - Pair Cards |
User | asi1024 |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 2644 Byte |
Status | AC |
Exec Time | 47 ms |
Memory | 6528 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 | 3 ms | 256 KB |
01-02.txt | AC | 38 ms | 892 KB |
01-03.txt | AC | 37 ms | 892 KB |
01-04.txt | AC | 37 ms | 896 KB |
01-05.txt | AC | 36 ms | 768 KB |
01-06.txt | AC | 36 ms | 896 KB |
01-07.txt | AC | 35 ms | 768 KB |
01-08.txt | AC | 35 ms | 896 KB |
01-09.txt | AC | 38 ms | 896 KB |
01-10.txt | AC | 42 ms | 2688 KB |
01-11.txt | AC | 47 ms | 5376 KB |
01-12.txt | AC | 33 ms | 896 KB |
01-13.txt | AC | 35 ms | 2040 KB |
01-14.txt | AC | 37 ms | 788 KB |
01-15.txt | AC | 36 ms | 896 KB |
01-16.txt | AC | 36 ms | 1024 KB |
01-17.txt | AC | 34 ms | 768 KB |
01-18.txt | AC | 36 ms | 1152 KB |
01-19.txt | AC | 37 ms | 1408 KB |
01-20.txt | AC | 45 ms | 6528 KB |
01-21.txt | AC | 36 ms | 768 KB |
01-22.txt | AC | 35 ms | 768 KB |
01-23.txt | AC | 34 ms | 896 KB |
01-24.txt | AC | 33 ms | 896 KB |
01-25.txt | AC | 36 ms | 1920 KB |
01-26.txt | AC | 39 ms | 4096 KB |
01-27.txt | AC | 26 ms | 4992 KB |
01-28.txt | AC | 8 ms | 3456 KB |
01-29.txt | AC | 5 ms | 1536 KB |
01-30.txt | AC | 7 ms | 3328 KB |
sample-01.txt | AC | 3 ms | 256 KB |
sample-02.txt | AC | 3 ms | 256 KB |