Submission #993332


Source Code Expand

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int N, M;
int X[100005];
int cnt[100005];
int mod[100005];

int main() {
    cin >> N >> M;
    rep(i, N) cin >> X[i];
    rep(i, N) cnt[X[i]]++;
    rep(i, N) mod[X[i] % M]++;
    int ans = 0;
    rep(i, M / 2 + 1) {
        if (i == 0) {
            ans += mod[0] / 2;
            continue;
        }

        int c = min(mod[i], mod[M - i]);
        ans += c;
        int a = max(mod[i], mod[M - 1]);
        int d = a - c;
        int j = mod[i] == c ? M - i : i;

        for (int k = j; k < 100001; k += j) {
            if (cnt[k] % 2 == 1) {
                cnt[k]--;
                d--;
            }
            if (d == 0) break;
        }
        // printf("%d %d\n", i, ans);
        ans += (mod[j] - c - d) / 2;
        // printf("%d %d\n", i, ans);
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task D - Pair Cards
User odan
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1424 Byte
Status WA
Exec Time 38 ms
Memory 1408 KB

Judge Result

Set Name sample all
Score / Max Score 0 / 0 0 / 700
Status
AC × 2
AC × 6
WA × 26
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 2 ms 256 KB
01-02.txt AC 35 ms 1024 KB
01-03.txt WA 36 ms 1024 KB
01-04.txt AC 36 ms 1024 KB
01-05.txt WA 35 ms 1024 KB
01-06.txt AC 36 ms 1024 KB
01-07.txt WA 35 ms 1024 KB
01-08.txt WA 38 ms 1024 KB
01-09.txt WA 35 ms 1024 KB
01-10.txt WA 36 ms 1152 KB
01-11.txt WA 37 ms 1408 KB
01-12.txt WA 36 ms 640 KB
01-13.txt WA 36 ms 640 KB
01-14.txt WA 36 ms 1024 KB
01-15.txt WA 35 ms 1024 KB
01-16.txt WA 35 ms 1024 KB
01-17.txt WA 35 ms 1024 KB
01-18.txt WA 36 ms 1024 KB
01-19.txt WA 36 ms 1024 KB
01-20.txt WA 36 ms 1408 KB
01-21.txt WA 35 ms 1024 KB
01-22.txt WA 35 ms 1024 KB
01-23.txt WA 35 ms 1024 KB
01-24.txt WA 36 ms 1024 KB
01-25.txt WA 36 ms 1152 KB
01-26.txt WA 36 ms 1408 KB
01-27.txt WA 19 ms 896 KB
01-28.txt WA 4 ms 1024 KB
01-29.txt WA 3 ms 768 KB
01-30.txt WA 3 ms 384 KB
sample-01.txt AC 3 ms 256 KB
sample-02.txt AC 3 ms 256 KB