結果

問題 No.2165 Let's Play Nim!
ユーザー tnakao0123tnakao0123
提出日時 2022-12-18 21:47:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,440 bytes
コンパイル時間 459 ms
コンパイル使用メモリ 59,484 KB
実行使用メモリ 35,164 KB
平均クエリ数 2.72
最終ジャッジ日時 2023-08-11 09:11:35
合計ジャッジ時間 11,262 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
23,772 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
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;

enum { First = 1, Second = 0 };

/* typedef */

typedef pair<int,int> pii;
typedef set<pii,greater<pii> > spiig;

/* global variables */

int as[MAX_N];

/* subroutines */

int my_act(spiig &ps, int x) {
  pii e = *ps.begin();
  int ai = e.first, i = e.second;
  int k = ai - (x ^ ai);

  ps.erase(ps.begin());
  if (ai > k) ps.insert(pii(ai - k, i));
  as[i] -= k;

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

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

  spiig::iterator sit = ps.find(pii(as[i], i));
  int ai = sit->first;

  ps.erase(sit);
  if (ai > k) ps.insert(pii(ai - k, i));
  as[i] -= k;

  return (r < 0) ? -1 : ai ^ as[i];
}

/* main */

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

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

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

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

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

  return 0;
}
0