CODE FESTIVAL 2016 Final

Submission #993800

Source codeソースコード

#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 = 100'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]);
  }
  cout << count << endl;
  return 0;
}

Submission

Task問題 D - Pair Cards
User nameユーザ名 StoneDot
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 WA
Score得点 0
Source lengthソースコード長 1467 Byte
File nameファイル名
Exec time実行時間 ms
Memory usageメモリ使用量 -

Test case

Set

Set name Score得点 / Max score Cases
sample - sample-01.txt,sample-02.txt
all 0 / 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 3 ms 640 KB
01-02.txt AC 31 ms 1152 KB
01-03.txt AC 31 ms 1024 KB
01-04.txt WA
01-05.txt WA
01-06.txt WA
01-07.txt WA
01-08.txt WA
01-09.txt WA
01-10.txt WA
01-11.txt WA
01-12.txt AC 31 ms 1024 KB
01-13.txt AC 32 ms 1664 KB
01-14.txt AC 31 ms 1024 KB
01-15.txt AC 31 ms 1024 KB
01-16.txt AC 31 ms 1024 KB
01-17.txt AC 34 ms 1024 KB
01-18.txt AC 31 ms 1024 KB
01-19.txt AC 31 ms 1280 KB
01-20.txt AC 35 ms 2560 KB
01-21.txt AC 31 ms 1024 KB
01-22.txt WA
01-23.txt WA
01-24.txt WA
01-25.txt WA
01-26.txt WA
01-27.txt AC 19 ms 2432 KB
01-28.txt WA
01-29.txt AC 4 ms 1280 KB
01-30.txt AC 5 ms 2176 KB
sample-01.txt AC 3 ms 640 KB
sample-02.txt AC 3 ms 640 KB