Submission #992665


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MOD 1000000007
#define MP make_pair
#define PB push_back
typedef long long ll;

int N, M, cnt[100100], g[100100], odd[100100], ans;
vector<int> v[100100], n[100100];

int main () {
        scanf("%d %d", &N, &M);
        fo(i, 0, N) {
                int x;
                scanf("%d", &x);
                cnt[x%M]++;
                v[x%M].PB(x);
        }
        fo(i, 0, M) {
                sort(v[i].begin(), v[i].end());
                fo(j, 0, (int) v[i].size()) {
                        if (!j || v[i][j-1] != v[i][j]) {
                                int x = j; while (x+1 < (int) v[i].size() && v[i][x+1] == v[i][j]) x++;
                                n[i].PB(x-j+1);
                                if (n[i].back()&1) odd[i]++, g[i] += x-j;
                                else g[i] += x-j+1;
                        }
                }
        }

        ans = cnt[0]/2;
        if (M%2 == 0) ans += cnt[M/2]/2;

        for (int i = 1; i < M-i; i++) {
                int a = i, b = M-i;
                if (odd[a] > odd[b]) swap(a, b);
                ans += odd[a], odd[b] -= odd[a], odd[a] = 0;
                while (odd[b] >= 2 && g[a] >= 2) odd[b] -= 2, g[a] -= 2, ans += 2;
                ans += g[a]/2 + g[b]/2;
        }

        printf("%d\n", ans);
        return 0;
}

Submission Info

Submission Time
Task D - Pair Cards
User gongy
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1443 Byte
Status AC
Exec Time 35 ms
Memory 12416 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:13:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &N, &M);
                               ^
./Main.cpp:16:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
                 scanf("%d", &x);
                                ^

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 7 ms 4992 KB
01-02.txt AC 25 ms 5880 KB
01-03.txt AC 25 ms 5756 KB
01-04.txt AC 25 ms 5880 KB
01-05.txt AC 24 ms 5760 KB
01-06.txt AC 24 ms 5760 KB
01-07.txt AC 23 ms 5760 KB
01-08.txt AC 23 ms 5888 KB
01-09.txt AC 25 ms 5888 KB
01-10.txt AC 31 ms 7808 KB
01-11.txt AC 34 ms 10112 KB
01-12.txt AC 19 ms 5628 KB
01-13.txt AC 20 ms 5628 KB
01-14.txt AC 24 ms 5904 KB
01-15.txt AC 24 ms 6016 KB
01-16.txt AC 24 ms 6272 KB
01-17.txt AC 23 ms 6016 KB
01-18.txt AC 26 ms 6656 KB
01-19.txt AC 28 ms 6400 KB
01-20.txt AC 35 ms 12416 KB
01-21.txt AC 23 ms 5504 KB
01-22.txt AC 22 ms 5504 KB
01-23.txt AC 21 ms 5504 KB
01-24.txt AC 21 ms 5632 KB
01-25.txt AC 34 ms 6144 KB
01-26.txt AC 25 ms 6912 KB
01-27.txt AC 22 ms 8832 KB
01-28.txt AC 9 ms 6272 KB
01-29.txt AC 8 ms 5504 KB
01-30.txt AC 8 ms 5376 KB
sample-01.txt AC 7 ms 4992 KB
sample-02.txt AC 7 ms 4992 KB