CODE FESTIVAL 2016 Final

Submission #1336629

Source codeソースコード

#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
vector<int> a[N];
int cnt[N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    int u = x % m;
    a[u].push_back(x);
  }
  for (int i = 0; i < m; ++i) {
    sort(a[i].begin(), a[i].end());
    for (int j = 0, k; j < a[i].size(); j = k) {
      for (k = j + 1; k < a[i].size() && a[i][j] == a[i][k]; ++k);
      cnt[i] += (k - j) / 2;
    }
  }
  int ret = 0;
  for (int i = 0; i * 2 <= m; ++i) {
    int j = m - i;
    if (i == 0 || i == j) {
      ret += a[i].size() / 2;
    } else {
      int cur = min(a[i].size(), a[j].size());
      ret += cur;
      ret += min(cnt[i], ((int)a[i].size() - cur) / 2);
      ret += min(cnt[j], ((int)a[j].size() - cur) / 2);
    }
  }
  printf("%d\n", ret);
  return 0;
}

Submission

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

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

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

Test case

Set

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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01-01.txt AC 2 ms 2560 KB
01-02.txt AC 19 ms 3196 KB
01-03.txt AC 19 ms 3196 KB
01-04.txt AC 18 ms 3200 KB
01-05.txt AC 18 ms 3200 KB
01-06.txt AC 18 ms 3328 KB
01-07.txt AC 18 ms 3072 KB
01-08.txt AC 17 ms 3200 KB
01-09.txt AC 17 ms 3200 KB
01-10.txt AC 21 ms 3968 KB
01-11.txt AC 22 ms 4992 KB
01-12.txt AC 14 ms 3196 KB
01-13.txt AC 14 ms 3196 KB
01-14.txt AC 18 ms 3092 KB
01-15.txt AC 18 ms 3200 KB
01-16.txt AC 17 ms 3328 KB
01-17.txt AC 16 ms 3072 KB
01-18.txt AC 17 ms 3456 KB
01-19.txt AC 19 ms 3456 KB
01-20.txt AC 21 ms 6144 KB
01-21.txt AC 17 ms 3200 KB
01-22.txt AC 17 ms 3072 KB
01-23.txt AC 16 ms 3200 KB
01-24.txt AC 15 ms 3200 KB
01-25.txt AC 17 ms 3456 KB
01-26.txt AC 18 ms 3712 KB
01-27.txt AC 11 ms 4352 KB
01-28.txt AC 4 ms 3072 KB
01-29.txt AC 3 ms 2816 KB
01-30.txt AC 3 ms 2688 KB
sample-01.txt AC 2 ms 2560 KB
sample-02.txt AC 2 ms 2560 KB