CODE FESTIVAL 2016 Final

Submission #11221582

Source codeソースコード

#include <bits/stdc++.h>

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

constexpr int MOD = 1000000007;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

template <class T>
string to_string(T s);
template <class S, class T>
string to_string(pair<S, T> p);
string to_string(string s) { return s; }
string to_string(const char s[]) { return to_string(string(s)); }

template <class T>
string to_string(T v) {
  if (v.empty()) return "{}";
  string ret = "{";
  for (auto x : v) ret += to_string(x) + ",";
  ret.back() = '}';
  return ret;
}
template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

void debug() { cerr << endl; }
template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

struct IO {
#ifdef _WIN32
  inline char getchar_unlocked() { return getchar(); }
  inline void putchar_unlocked(char c) { putchar(c); }
#endif
  string separator = " ";
  template <class T>
  inline void read(T& x) {
    char c;
    do {
      c = getchar_unlocked();
    } while (c != '-' && (c < '0' || '9' < c));
    bool minus = 0;
    if (c == '-') {
      minus = 1;
      c = getchar_unlocked();
    }
    x = 0;
    while ('0' <= c && c <= '9') {
      x *= 10;
      x += c - '0';
      c = getchar_unlocked();
    }
    if (minus) x = -x;
  }
  inline void read(string& x) {
    char c;
    do {
      c = getchar_unlocked();
    } while (c == ' ' || c == '\n');
    x.clear();
    do {
      x += c;
      c = getchar_unlocked();
    } while (c != ' ' && c != '\n' && c != EOF);
  }
  template <class T>
  inline void read(vector<T>& v) {
    for (auto& x : v) read(x);
  }
  template <class Head, class... Tail>
  inline void read(Head& head, Tail&... tail) {
    read(head);
    read(tail...);
  }
  template <class T>
  inline void write(T x) {
    char buf[32];
    int p = 0;
    if (x < 0) {
      x = -x;
      putchar_unlocked('-');
    }
    if (x == 0) putchar_unlocked('0');
    while (x > 0) {
      buf[p++] = (x % 10) + '0';
      x /= 10;
    }
    while (p) {
      putchar_unlocked(buf[--p]);
    }
  }
  inline void write(string x) {
    for (char c : x) putchar_unlocked(c);
  }
  inline void write(const char s[]) {
    for (int i = 0; s[i] != 0; ++i) putchar_unlocked(s[i]);
  }
  template <class T>
  inline void write(vector<T> v) {
    for (auto itr = v.begin(); itr + 1 != v.end(); ++itr) {
      write(*itr);
      write(separator);
    }
    write(v.back());
  }
  template <class Head, class... Tail>
  inline void write(Head head, Tail... tail) {
    write(head);
    write(separator);
    write(tail...);
  }
  template <class Head, class... Tail>
  inline void writeln(Head head, Tail... tail) {
    write(head, tail...);
    write("\n");
  }
  void set_separator(string s) { separator = s; }
} io;

int main() {
  int N, M;
  io.read(N, M);
  vector<int> X(N);
  io.read(X);
  vector<int> count_mod(M), pair_mod(M);
  map<int, int> cnt;
  REP(i, N) {
    count_mod[X[i] % M]++;
    cnt[X[i]]++;
  }
  for (auto p : cnt) pair_mod[p.first % M] += p.second / 2;
  int ans = 0;
  REP(i, M / 2 + 1) {
    if (i == 0 || i * 2 == M) {
      ans += count_mod[i] / 2;
    } else {
      int t = min(count_mod[i], count_mod[M - i]);
      ans += t;
      ans += min(pair_mod[i], (count_mod[i] - t) / 2);
      ans += min(pair_mod[M - i], (count_mod[M - i] - t) / 2);
    }
  }
  io.writeln(ans);
  return 0;
}

Submission

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