Submission #1800835


Source Code Expand

#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, M;
int X[100010];
int cnt[100010];
int mod[100010][2];

int get_cnt(int x) {
  return mod[x][0] + 2 * mod[x][1];
}

int same(int x) {
  int c = get_cnt(x);
  return c/2;
}

int odd(int x) {
  int c = get_cnt(x);
  int d = get_cnt(M - x);
  if (c < d) {
    swap(c, d);
    x = M - x;
  }
  int ans = d;
  if (d <= mod[x][0]) {
    ans += mod[x][1];
    return ans;
  } else {
    ans += (mod[x][1] * 2 - (d - mod[x][0]))/2;
    return ans;
  }
}

int main () {
  cin >> N >> M;
  for (auto i = 0; i < N; ++i) {
    cin >> X[i];
  }
  fill(cnt, cnt+100010, 0);
  for (auto i = 0; i < N; ++i) {
    cnt[X[i]]++;
  }
  fill(&mod[0][0], &mod[0][0]+100010*2, 0);
  for (auto i = 0; i < 100010; ++i) {
    mod[i%M][0] += cnt[i]%2;
    mod[i%M][1] += cnt[i]/2;
  }
  int ans = 0;
  ans += same(0);
  for (auto i = 1; i < M/2; ++i) {
    ans += odd(i);
  }
  if (M%2 == 0) {
    ans += same(M/2);
  } else {
    ans += odd(M/2);
  }
  cout << ans << endl;
}

Submission Info

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

Judge Result

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