Submission #6364235


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

const int N = 100 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, m;
int a[N];

bool read() {
    if (!(cin >> n >> m))
        return false;

    for (int i = 0; i < n; ++i)
        cin >> a[i];

    return true;
}

void solve() {
    auto ans = 0;
    map<int, int> f, g, h;

    for (int i = 0; i < n; ++i)
        ++(a[i] % m == 0 ? ans : f[a[i]]);

    ans /= 2;

    for (auto p : f) {
        ans += p.second / 2;

        if (p.second >= 2)
            h[p.first % m] += p.second / 2;

        if (p.second & 1)
            ++g[p.first % m];
    }

    for (int k = 1; k + k <= m; ++k)
        if (k + k < m) {
            auto res = 0;

            for (int t = 0; t <= min(g[k], g[m - k]); ++t)
                res = max(res, t + min(h[m - k], (g[k] - t) / 2) + min(h[k], (g[m - k] - t) / 2));

            ans += res;
        } else {
            ans += g[k] / 2;
        }

    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}

Submission Info

Submission Time
Task D - Pair Cards
User serezhae
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1171 Byte
Status AC
Exec Time 160 ms
Memory 14720 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 34
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 2 ms 384 KB
01-02.txt AC 9 ms 640 KB
01-03.txt AC 21 ms 2176 KB
01-04.txt AC 27 ms 2688 KB
01-05.txt AC 29 ms 2816 KB
01-06.txt AC 35 ms 3328 KB
01-07.txt AC 37 ms 3456 KB
01-08.txt AC 41 ms 3712 KB
01-09.txt AC 43 ms 3840 KB
01-10.txt AC 60 ms 7424 KB
01-11.txt AC 85 ms 13056 KB
01-12.txt AC 9 ms 640 KB
01-13.txt AC 37 ms 4864 KB
01-14.txt AC 25 ms 2944 KB
01-15.txt AC 37 ms 4352 KB
01-16.txt AC 47 ms 5248 KB
01-17.txt AC 51 ms 5376 KB
01-18.txt AC 54 ms 5632 KB
01-19.txt AC 63 ms 6528 KB
01-20.txt AC 160 ms 14720 KB
01-21.txt AC 13 ms 768 KB
01-22.txt AC 16 ms 768 KB
01-23.txt AC 17 ms 896 KB
01-24.txt AC 18 ms 896 KB
01-25.txt AC 31 ms 3712 KB
01-26.txt AC 68 ms 10240 KB
01-27.txt AC 86 ms 12160 KB
01-28.txt AC 49 ms 9856 KB
01-29.txt AC 19 ms 3968 KB
01-30.txt AC 76 ms 9600 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB