Submission #13494511


Source Code Expand

Copy
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
using vi = vector<int>;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))
int main() {
  int N, M;
  ins(N, M);

  vi X(N);
  rep(i, N)
    cin >> X[i];
  all(sort, X);

  vector<int> m(M, 0), p(M, 0);
  int ans = 0;
  map<int, int> count;
  rep(i, N)
    ++count[X[i]];

  for (const auto& e:count) {
    int X = e.second;
    int r = (M - e.first % M) % M,
        r2 = e.first % M;
    if (m[r] >= X) {
      ans += X;
      m[r] -= X;
      X = 0;
      continue;
    }
    ans += m[r];
    X -= m[r];
    m[r] = 0;
    if (p[r] >= X) {
      int n = p[r] - X;
      ans += X;
      p[r] = n - (n%2);
      m[r] = n % 2;
    } else {
      // p[r]枚すべて使ってペアをつくる
      ans += p[r]/2;
      X -= p[r];
      p[r] = 0;
      p[r2] += X-(X%2);
      m[r2] += X % 2;
    }
  }
  rep(i, M)
    ans += p[i] / 2;
  cout << ans << endl;

  return 0;
}

Submission Info

Submission Time
Task D - Pair Cards
User pandanoir
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1167 Byte
Status
Exec Time 61 ms
Memory 6144 KB

Judge Result

Set Name Score / Max Score Test Cases
sample 0 / 0 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, sample-01.txt, sample-02.txt
Case Name Status Exec Time Memory
01-01.txt 1 ms 256 KB
01-02.txt 55 ms 3584 KB
01-03.txt 54 ms 3584 KB
01-04.txt 54 ms 3584 KB
01-05.txt 53 ms 3584 KB
01-06.txt 54 ms 3584 KB
01-07.txt 54 ms 3584 KB
01-08.txt 53 ms 3584 KB
01-09.txt 53 ms 3584 KB
01-10.txt 54 ms 3968 KB
01-11.txt 54 ms 4352 KB
01-12.txt 30 ms 640 KB
01-13.txt 31 ms 1024 KB
01-14.txt 60 ms 5376 KB
01-15.txt 60 ms 5376 KB
01-16.txt 59 ms 5376 KB
01-17.txt 61 ms 5376 KB
01-18.txt 60 ms 5376 KB
01-19.txt 61 ms 5376 KB
01-20.txt 60 ms 6144 KB
01-21.txt 38 ms 768 KB
01-22.txt 37 ms 768 KB
01-23.txt 37 ms 768 KB
01-24.txt 37 ms 768 KB
01-25.txt 37 ms 1024 KB
01-26.txt 38 ms 1536 KB
01-27.txt 28 ms 3584 KB
01-28.txt 3 ms 1152 KB
01-29.txt 2 ms 640 KB
01-30.txt 2 ms 1024 KB
sample-01.txt 1 ms 256 KB
sample-02.txt 1 ms 256 KB