結果

問題 No.2165 Let's Play Nim!
ユーザー tnakao0123tnakao0123
提出日時 2022-12-19 01:40:02
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,533 bytes
コンパイル時間 717 ms
コンパイル使用メモリ 60,484 KB
実行使用メモリ 24,384 KB
平均クエリ数 800.44
最終ジャッジ日時 2023-08-11 09:24:11
合計ジャッジ時間 8,043 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
23,484 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 93 ms
23,940 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 142 ms
24,252 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 45 ms
23,364 KB
testcase_23 AC 44 ms
23,508 KB
testcase_24 WA -
testcase_25 AC 78 ms
24,312 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 TLE -
testcase_31 -- -
testcase_32 -- -
evil_2_big_1.txt -- -
evil_2_big_2.txt -- -
evil_2_big_3.txt -- -
evil_big_1.txt -- -
evil_big_2.txt -- -
evil_big_3.txt -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2165.cc:  No.2165 Let's Play Nim! - yukicoder
 */

#include<cstdio>
#include<set>
#include<algorithm>
#include<utility>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 75000;
const int BN = 17;

enum { First = 1, Second = 0 };

/* typedef */

typedef pair<int,int> pii;
typedef set<pii> spii;

/* global variables */

int as[MAX_N];
spii bps[BN];

/* subroutines */

inline int msb(int x) {
  int k = 0, bk = 1;
  while ((bk << 1) <= x) k++, bk <<= 1;
  //printf("msb(%d)=%d\n", x, k);
  return k;
}

void replace(int i, int ai) {
  bps[msb(as[i])].erase(pii(as[i], i));
  if (ai > 0) bps[msb(ai)].insert(pii(ai, i));
  as[i] = ai;
}

int my_act(int x) {
  int i = bps[msb(x)].begin()->second;
  int ai = x ^ as[i], k = as[i] - ai;
  replace(i, ai);

  printf("%d %d\n", i + 1, k); fflush(stdout);
  int r;
  scanf("%d", &r);
  return r;
}

int judge_act() {
  int i, k, r;
  scanf("%d%d%d", &i, &k, &r), i--;

  int ai = as[i] - k, x = as[i] ^ ai;
  replace(i, ai);

  return (r < 0) ? -1 : x;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  int x = 0;
  for (int i = 0; i < n; i++) {
    x ^= as[i];
    bps[msb(as[i])].insert(pii(as[i], i));
  }

  if (x != 0) {
    printf("%d\n", First), fflush(stdout);
    my_act(x);
  }
  else
    printf("%d\n", Second), fflush(stdout);

  for (;;) {
    int x = judge_act();
    if (x < 0) break;

    int r = my_act(x);
    if (r < 0) break;
  }

  return 0;
}
0