結果

問題 No.2165 Let's Play Nim!
ユーザー KudeKude
提出日時 2022-12-16 09:01:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 2,283 bytes
コンパイル時間 2,264 ms
コンパイル使用メモリ 202,336 KB
実行使用メモリ 27,952 KB
平均クエリ数 889.28
最終ジャッジ日時 2023-08-09 17:20:09
合計ジャッジ時間 17,298 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
27,916 KB
testcase_01 AC 130 ms
27,732 KB
testcase_02 AC 145 ms
27,520 KB
testcase_03 AC 101 ms
27,420 KB
testcase_04 AC 29 ms
27,264 KB
testcase_05 AC 34 ms
27,176 KB
testcase_06 AC 33 ms
27,596 KB
testcase_07 AC 32 ms
27,656 KB
testcase_08 AC 108 ms
27,952 KB
testcase_09 AC 31 ms
27,944 KB
testcase_10 AC 38 ms
27,256 KB
testcase_11 AC 144 ms
27,304 KB
testcase_12 AC 130 ms
27,544 KB
testcase_13 AC 29 ms
27,400 KB
testcase_14 AC 34 ms
27,700 KB
testcase_15 AC 30 ms
27,860 KB
testcase_16 AC 126 ms
27,680 KB
testcase_17 AC 73 ms
27,592 KB
testcase_18 AC 202 ms
27,316 KB
testcase_19 AC 29 ms
27,644 KB
testcase_20 AC 32 ms
27,444 KB
testcase_21 AC 57 ms
27,788 KB
testcase_22 AC 47 ms
27,868 KB
testcase_23 AC 45 ms
27,836 KB
testcase_24 AC 42 ms
27,840 KB
testcase_25 AC 85 ms
27,372 KB
testcase_26 AC 144 ms
27,328 KB
testcase_27 AC 51 ms
27,644 KB
testcase_28 AC 76 ms
27,748 KB
testcase_29 AC 28 ms
27,792 KB
testcase_30 AC 28 ms
27,348 KB
testcase_31 AC 28 ms
27,392 KB
testcase_32 AC 65 ms
27,476 KB
evil_2_big_1.txt AC 1,357 ms
27,912 KB
evil_2_big_2.txt AC 1,676 ms
28,100 KB
evil_2_big_3.txt AC 1,353 ms
27,512 KB
evil_big_1.txt AC 1,622 ms
27,604 KB
evil_big_2.txt AC 1,756 ms
28,136 KB
evil_big_3.txt AC 1,710 ms
28,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;

template<int element_size>
struct array_set {
  int state[element_size];  // -1 if not in set else index in elems
  int elems[element_size];
  int size = 0;
  array_set() { memset(state, -1, sizeof(int) * element_size); }
  void insert(int x) {
    if (state[x] == -1) {
      state[x] = size;
      elems[size] = x;
      size++;
    }
  }
  bool contains(int x) { return state[x] != -1; }
  int* begin() { return elems; }
  int* end() { return elems + size; }
  void clear() { while(size) state[elems[--size]] = -1; }
  void erase(int x) {  // not tested
    int idx = state[x];
    if (idx != -1) {
      state[x] = -1;
      size--;
      if (idx != size) {
        int y = elems[size];
        state[y] = idx;
        elems[idx] = y;
      }
    }
  }
};

constexpr int M = 75000;

array_set<M> st[17];

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI a(n);
  rep(i, n) {
    cin >> a[i];
    rep(k, 17) if (a[i] >> k & 1) st[k].insert(i);
  }
  int g = 0;
  rrep(i, n) g ^= a[i];
  cout << int(g != 0) << endl;
  while(true) {
    if (g) {
      int msb = 31 - __builtin_clz(g);
      int i = st[msb].elems[0];
      int x = a[i], nx = x ^ g;
      a[i] = nx;
      cout << i + 1 << ' ' << x - nx << endl;
      rrep(k, msb + 1) if (g >> k & 1) {
        if (x >> k & 1) st[k].erase(i);
        else st[k].insert(i);
      }
      g = 0;
    } else {
      int i, dec;
      cin >> i >> dec;
      i--;
      int x = a[i], nx = x - dec;
      a[i] = nx;
      g = x ^ nx;
      rrep(k, 17) if (g >> k & 1) {
        if (x >> k & 1) st[k].erase(i);
        else st[k].insert(i);
      }
    }
    int ret;
    cin >> ret;
    if (ret == -1) exit(0);
  }
}
0