Submission #992790


Source Code Expand

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
#define repeat_from_reverse(i,m,n) for (int i = (n)-1; (i) >= (m); --(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
typedef long long ll;
using namespace std;
template <class T> void setmax(T & a, T const & b) { if (a < b) a = b; }
template <class T> void setmin(T & a, T const & b) { if (b < a) a = b; }
template <typename T, typename X> auto vectors(T a, X x) { return vector<T>(x, a); }
template <typename T, typename X, typename Y, typename... Zs> auto vectors(T a, X x, Y y, Zs... zs) { auto cont = vectors(a, y, zs...); return vector<decltype(cont)>(x, cont); }
template <typename T> T input(istream & in) { T a; in >> a; return a; }
int main() {
    // input
    int n, m; cin >> n >> m;
    map<int,int> xs;
    repeat (i,n) {
        int x; cin >> x;
        xs[x] += 1;
    }
    // compute
    vector<int> cnt(m), pr(m);
    for (auto it : xs) {
        int x, k; tie(x, k) = it;
        cnt[x % m] += k;
        pr [x % m] += k / 2 * 2;
    }
    int ans = 0;
    repeat (i,m) {
        int j = (m - i) % m;
        if (i == j) {
            ans += cnt[i] / 2;
        } else if (i < j) {
            int k = min(cnt[i], cnt[j]);
            ans += k;
            ans += min(cnt[i] - k, pr[i]) / 2;
            ans += min(cnt[j] - k, pr[j]) / 2;
        }
    }
    // output
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task D - Pair Cards
User kimiyuki
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1866 Byte
Status AC
Exec Time 69 ms
Memory 5760 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 700 / 700
Status
AC × 2
AC × 32
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 59 ms 3200 KB
01-03.txt AC 60 ms 3200 KB
01-04.txt AC 60 ms 3200 KB
01-05.txt AC 60 ms 3200 KB
01-06.txt AC 60 ms 3200 KB
01-07.txt AC 59 ms 3200 KB
01-08.txt AC 60 ms 3200 KB
01-09.txt AC 59 ms 3200 KB
01-10.txt AC 60 ms 3584 KB
01-11.txt AC 61 ms 3968 KB
01-12.txt AC 30 ms 384 KB
01-13.txt AC 31 ms 640 KB
01-14.txt AC 68 ms 4864 KB
01-15.txt AC 68 ms 4992 KB
01-16.txt AC 68 ms 4864 KB
01-17.txt AC 68 ms 4992 KB
01-18.txt AC 68 ms 4992 KB
01-19.txt AC 67 ms 4992 KB
01-20.txt AC 69 ms 5760 KB
01-21.txt AC 39 ms 384 KB
01-22.txt AC 39 ms 384 KB
01-23.txt AC 39 ms 384 KB
01-24.txt AC 54 ms 512 KB
01-25.txt AC 39 ms 640 KB
01-26.txt AC 40 ms 1152 KB
01-27.txt AC 34 ms 3328 KB
01-28.txt AC 6 ms 1152 KB
01-29.txt AC 3 ms 640 KB
01-30.txt AC 4 ms 1024 KB
sample-01.txt AC 3 ms 256 KB
sample-02.txt AC 2 ms 256 KB