Submission #992278
Source Code Expand
#pragma comment(linker, "/STACK:512000000") #define _CRT_SECURE_NO_WARNINGS //#include "testlib.h" #include <bits/stdc++.h> using namespace std; #define all(a) a.begin(), a.end() typedef long long li; typedef long double ld; void solve(); void precalc(); clock_t start; //int timer = 1; int testNumber = 1; bool todo = true; int main() { #ifdef AIM freopen("/home/alexandero/ClionProjects/ACM/input.txt", "r", stdin); //freopen("out.txt", "w", stdout); #else //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); #endif start = clock(); int t = 1; cout.sync_with_stdio(0); cin.tie(0); precalc(); cout.precision(10); cout << fixed; //cin >> t; int testNum = 1; while (t--) { //cerr << testNum << endl; //cout << "Case #" << testNum++ << ": "; solve(); ++testNumber; //++timer; } #ifdef AIM cerr << "\n\n time: " << (clock() - start) / 1.0 / CLOCKS_PER_SEC << "\n\n"; #endif return 0; } //BE CAREFUL: IS INT REALLY INT? template<typename T> T binpow(T q, T w, T mod) { if (!w) return 1 % mod; if (w & 1) return q * 1LL * binpow(q, w - 1, mod) % mod; return binpow(q * 1LL * q % mod, w / 2, mod); } template<typename T> T gcd(T q, T w) { while (w) { q %= w; swap(q, w); } return q; } template<typename T> T lcm(T q, T w) { return q / gcd(q, w) * w; } void precalc() { } //#define int li //const int mod = 1000000007; vector<int> dsu; void init(int n) { dsu.resize(n); for (int i= 0; i < n; ++i) { dsu[i] = i; } } int find_set(int v) { if (dsu[v] == v) { return v; } return dsu[v] = find_set(dsu[v]); } void merge(int q, int w) { q = find_set(q); w = find_set(w); dsu[w] = q; } void solve() { int n, m; cin >> n >> m; vector<vector<int>> cards(m); for (int i = 0; i < n; ++i) { int x; cin >> x; cards[x % m].push_back(x); } vector<int> sum(m), odd(m); for (int i = 0; i < m; ++i) { sum[i] = cards[i].size(); sort(all(cards[i])); for (int j = 0; j < cards[i].size(); ) { int r = j; while (r < cards[i].size() && cards[i][j] == cards[i][r]) { ++r; } int cnt = r - j; if (cnt & 1) { ++odd[i]; } j = r; } } int dp = 0; for (int i = 1; i < (m + 1) / 2; ++i) { int j = m - i; int new_dp = -1; for (int x = 0; x <= sum[i] && x <= sum[j]; ++x) { int even_i; if (x <= odd[i]) { even_i = sum[i] - odd[i]; } else { even_i = sum[i] - x; } int even_j; if (x <= odd[j]) { even_j = sum[j] - odd[j]; } else { even_j = sum[j] - x; } new_dp = max(new_dp, dp + x + even_i / 2 + even_j / 2); //cout << i << ' ' << j << ' ' << even_i << ' ' << even_j << ' ' << x << "\n"; } //cout << new_dp << "\n"; dp = new_dp; } dp += sum[0] / 2; if (m % 2 == 0) { dp += sum[m / 2] / 2; } cout << dp << "\n"; }
Submission Info
Submission Time | |
---|---|
Task | D - Pair Cards |
User | Kostroma |
Language | C++14 (GCC 5.4.1) |
Score | 700 |
Code Size | 3588 Byte |
Status | AC |
Exec Time | 25 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 | 18 ms | 892 KB |
01-03.txt | AC | 18 ms | 892 KB |
01-04.txt | AC | 18 ms | 896 KB |
01-05.txt | AC | 17 ms | 768 KB |
01-06.txt | AC | 17 ms | 896 KB |
01-07.txt | AC | 16 ms | 640 KB |
01-08.txt | AC | 16 ms | 896 KB |
01-09.txt | AC | 16 ms | 896 KB |
01-10.txt | AC | 22 ms | 2688 KB |
01-11.txt | AC | 25 ms | 5376 KB |
01-12.txt | AC | 13 ms | 892 KB |
01-13.txt | AC | 15 ms | 2040 KB |
01-14.txt | AC | 17 ms | 788 KB |
01-15.txt | AC | 17 ms | 896 KB |
01-16.txt | AC | 16 ms | 1024 KB |
01-17.txt | AC | 15 ms | 768 KB |
01-18.txt | AC | 17 ms | 1280 KB |
01-19.txt | AC | 18 ms | 1408 KB |
01-20.txt | AC | 25 ms | 6528 KB |
01-21.txt | AC | 16 ms | 896 KB |
01-22.txt | AC | 16 ms | 768 KB |
01-23.txt | AC | 15 ms | 896 KB |
01-24.txt | AC | 14 ms | 896 KB |
01-25.txt | AC | 17 ms | 1920 KB |
01-26.txt | AC | 20 ms | 4096 KB |
01-27.txt | AC | 15 ms | 4992 KB |
01-28.txt | AC | 7 ms | 3456 KB |
01-29.txt | AC | 4 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 |