Submission #994135


Source Code Expand

Copy
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define SREP(s,i,m) for(unsigned int i = s; i < m; ++i)
#define REP(i,m) SREP(0,i,m)
using namespace std;

#ifdef _MSC_VER
using LONG = __int64;
using ULONG = unsigned __int64;
#else
using LONG = long long int;
using ULONG = unsigned long long int;
#endif

const int MAX_X = 101'000;
// 二乗を計算する。
int sq(int x) { return x * x; }
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> X(N);
  REP(i, N) {
    cin >> X[i];
  }
  vector<int> box(M);
  vector<int> box2(MAX_X);
  vector<int> used(M);
  REP(i, N) {
    box[X[i] % M]++;
    box2[X[i]]++;
  }
  used[0] = box[0];
  SREP(1, i, (M + 1) / 2) {
    used[M - i] = used[i] = min(box[i], box[M - i]);
  }
  if (M % 2 == 0) {
    int idx = M / 2;
    used[idx] = box[idx];
  }
  int count = 0;
  count += used[0] / 2;
  SREP(1, i, (M + 1) / 2) {
    count += used[i];
  }
  if (M % 2 == 0) {
    int idx = M / 2;
    count += used[idx] / 2;
  }
  vector<int> rest(M);
  REP(i, M) {
    rest[i] = box[i] - used[i];
  }
  vector<int> pair_count(M);
  REP(i, MAX_X) {
    int m = i % M;
    pair_count[m] += box2[i] / 2;
  }
  REP(i, M) {
    count += min(pair_count[i], rest[i] / 2);
  }
  cout << count << endl;
  return 0;
}

Submission Info

Submission Time
Task D - Pair Cards
User StoneDot
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1471 Byte
Status
Exec Time 34 ms
Memory 2560 KB

Judge Result

Set Name Score / Max Score Test Cases
sample 0 / 0 sample-01.txt, sample-02.txt
all 700 / 700 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 3 ms 640 KB
01-02.txt 32 ms 1024 KB
01-03.txt 31 ms 1024 KB
01-04.txt 31 ms 1024 KB
01-05.txt 31 ms 1024 KB
01-06.txt 31 ms 1024 KB
01-07.txt 31 ms 1024 KB
01-08.txt 32 ms 1024 KB
01-09.txt 31 ms 1024 KB
01-10.txt 32 ms 1664 KB
01-11.txt 34 ms 2560 KB
01-12.txt 31 ms 1024 KB
01-13.txt 32 ms 1664 KB
01-14.txt 31 ms 1024 KB
01-15.txt 31 ms 1024 KB
01-16.txt 31 ms 1024 KB
01-17.txt 31 ms 1024 KB
01-18.txt 31 ms 1024 KB
01-19.txt 32 ms 1280 KB
01-20.txt 34 ms 2560 KB
01-21.txt 31 ms 1024 KB
01-22.txt 31 ms 1024 KB
01-23.txt 31 ms 1024 KB
01-24.txt 31 ms 1024 KB
01-25.txt 32 ms 1536 KB
01-26.txt 34 ms 2560 KB
01-27.txt 19 ms 2432 KB
01-28.txt 7 ms 2176 KB
01-29.txt 4 ms 1280 KB
01-30.txt 6 ms 2176 KB
sample-01.txt 3 ms 640 KB
sample-02.txt 3 ms 640 KB