CODE FESTIVAL 2016 Final

Submission #992611

Source codeソースコード

#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

int n, m;
int x[111111];
vector<int> y[111111];
int z[111111];

int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", x+i);
    y[x[i]%m].push_back(x[i]);
  }

  int res = 0;
  memset(z, -1, sizeof(z));
  for (int i = 0; i < m; i++) {
    if (z[i] >= 0) continue;
    int p = i;
    int q = (m-i)%m;
    if (p == q) {
      z[p] = y[p].size();
      res += z[p]/2;
    } else {
      z[p] = z[q] = min(y[p].size(), y[q].size());
      res += z[p];
    }
  }

  for (int i = 0; i < m; i++) {
    // printf("%d/%zd\n", z[i], y[i].size());
    for (int j = 0; j < int(y[i].size())-1; j++) {
      if (y[i][j] == y[i][j+1] && z[i]+2 <= int(y[i].size())) {
        z[i] += 2;
        res += 1;
        j++;
      }
    }
  }
  
  printf("%d\n", res);
  return 0;
}

/*
  1 1 2 3 4 5 9
  0: 5
  1: 4 9
  2: 3
  3: 2
  4: 1 1
 */

/*
  15 10
  1 5 6 10 11 11 11 20 21 25 25 26 99 99 99
 */

Submission

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

Compiler messageコンパイルメッセージ

./Main.cpp: In function ‘int main()’:
./Main.cpp:14:24: 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:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", x+i);
^

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 5 ms 3328 KB
01-02.txt AC 16 ms 4344 KB
01-03.txt AC 16 ms 4220 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 AC 25 ms 5632 KB
01-12.txt AC 16 ms 4216 KB
01-13.txt AC 16 ms 4216 KB
01-14.txt AC 16 ms 4240 KB
01-15.txt AC 16 ms 4352 KB
01-16.txt AC 16 ms 4352 KB
01-17.txt AC 17 ms 4224 KB
01-18.txt AC 19 ms 4480 KB
01-19.txt AC 22 ms 4480 KB
01-20.txt AC 25 ms 6784 KB
01-21.txt AC 16 ms 4160 KB
01-22.txt WA
01-23.txt WA
01-24.txt WA
01-25.txt WA
01-26.txt AC 20 ms 4352 KB
01-27.txt AC 15 ms 4992 KB
01-28.txt AC 6 ms 3328 KB
01-29.txt AC 6 ms 3328 KB
01-30.txt AC 6 ms 3328 KB
sample-01.txt AC 5 ms 3328 KB
sample-02.txt AC 5 ms 3328 KB