CODE FESTIVAL 2016 Final

Submission #10086545

Source codeソースコード

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> X(N);
  rep(i, N) {
    cin >> X[i];
  }

  map<int, int> m;
  vector<ll> cnt(M), cnt_pair(M);
  rep(i, N) {
    cnt[X[i] % M]++;
    m[X[i]]++;
    if (m[X[i]] % 2 == 0)
      cnt_pair[X[i] % M]++;
  }
  // debug(cnt);
  // debug(cnt_pair);

  ll ans = 0;
  repp(i, 1, (M - 1) / 2) {
    int l = i, s = M - i;
    if (cnt[l] < cnt[s])
      swap(l, s);
    ans += cnt[s];
    ans += min(cnt_pair[l], (cnt[l] - cnt[s]) / 2);
  }

  ans += cnt[0] / 2;
  if (M % 2 == 0)
    ans += cnt[M / 2] / 2;
  cout << ans << endl;
}

Submission

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

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 1 ms 256 KB
01-02.txt AC 44 ms 3968 KB
01-03.txt AC 45 ms 3968 KB
01-04.txt AC 44 ms 3968 KB
01-05.txt AC 44 ms 3968 KB
01-06.txt AC 44 ms 3968 KB
01-07.txt AC 44 ms 3968 KB
01-08.txt AC 44 ms 3968 KB
01-09.txt AC 45 ms 4096 KB
01-10.txt AC 46 ms 4608 KB
01-11.txt AC 47 ms 5632 KB
01-12.txt AC 11 ms 1024 KB
01-13.txt AC 12 ms 1792 KB
01-14.txt AC 50 ms 5760 KB
01-15.txt AC 51 ms 5760 KB
01-16.txt AC 51 ms 5760 KB
01-17.txt AC 51 ms 5760 KB
01-18.txt AC 51 ms 5760 KB
01-19.txt AC 51 ms 5888 KB
01-20.txt AC 52 ms 7296 KB
01-21.txt AC 26 ms 1280 KB
01-22.txt AC 26 ms 1280 KB
01-23.txt AC 26 ms 1280 KB
01-24.txt AC 26 ms 1280 KB
01-25.txt AC 27 ms 1664 KB
01-26.txt AC 27 ms 2816 KB
01-27.txt AC 25 ms 4608 KB
01-28.txt AC 3 ms 2048 KB
01-29.txt AC 2 ms 896 KB
01-30.txt AC 2 ms 1792 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB