CODE FESTIVAL 2016 Final

Submission #5431355

Source codeソースコード

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pill;

int modCount[100005];
int pairs[100005];
void solve() {
  int n, m;
  cin >> n >> m;
  map<int, int> dp;
  for(int i = 0; i < n; i++) {
    int t;
    cin >> t;
    modCount[t%m]++;
    dp[t]++;
  }
  for(auto x: dp) {
    pairs[(x.first%m)] += x.second / 2;
  }
  int ret = 0;
  {
    int zero = modCount[0]/2;
    ret += zero;
    modCount[0] -= 2 * zero;
  }
  {
    if(m%2 == 0) {
      int zero = modCount[m/2]/2;
      ret += zero;
      modCount[m/2] -= 2 * zero;
    }
  }
  for(int i = 1; i < m-i; i++) {
    int j = m-i;
    int take = min(modCount[i], modCount[j]);
    modCount[i] -= take;
    modCount[j] -= take;
    ret += take;
  }
  for(int i = 0; i < m; i++) {
    ret += min(pairs[i], modCount[i]/2);
  }
  cout << ret << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}

Submission

Task問題 D - Pair Cards
User nameユーザ名 xiaowuc1
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 700
Source lengthソースコード長 1351 Byte
File nameファイル名
Exec time実行時間 50 ms
Memory usageメモリ使用量 5760 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 38 ms 3200 KB
01-03.txt AC 37 ms 3200 KB
01-04.txt AC 38 ms 3200 KB
01-05.txt AC 38 ms 3200 KB
01-06.txt AC 37 ms 3200 KB
01-07.txt AC 39 ms 3200 KB
01-08.txt AC 40 ms 3200 KB
01-09.txt AC 39 ms 3200 KB
01-10.txt AC 38 ms 3584 KB
01-11.txt AC 39 ms 3968 KB
01-12.txt AC 9 ms 256 KB
01-13.txt AC 10 ms 384 KB
01-14.txt AC 46 ms 4992 KB
01-15.txt AC 47 ms 4992 KB
01-16.txt AC 48 ms 4992 KB
01-17.txt AC 49 ms 4992 KB
01-18.txt AC 49 ms 4992 KB
01-19.txt AC 49 ms 4992 KB
01-20.txt AC 50 ms 5760 KB
01-21.txt AC 18 ms 384 KB
01-22.txt AC 18 ms 512 KB
01-23.txt AC 19 ms 512 KB
01-24.txt AC 18 ms 512 KB
01-25.txt AC 19 ms 640 KB
01-26.txt AC 19 ms 1280 KB
01-27.txt AC 22 ms 3200 KB
01-28.txt AC 3 ms 1152 KB
01-29.txt AC 2 ms 640 KB
01-30.txt AC 2 ms 640 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB