結果

問題 No.946 箱箱箱
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-12-09 03:44:54
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,261 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 67,340 KB
実行使用メモリ 4,472 KB
最終ジャッジ日時 2023-08-20 13:36:25
合計ジャッジ時間 2,450 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,356 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 3 ms
4,380 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 3 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 3 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 5 ms
4,472 KB
testcase_37 AC 4 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 3 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 5 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 4 ms
4,376 KB
testcase_46 AC 4 ms
4,380 KB
testcase_47 AC 2 ms
4,376 KB
testcase_48 AC 1 ms
4,380 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 1 ms
4,380 KB
testcase_51 AC 1 ms
4,380 KB
testcase_52 AC 1 ms
4,380 KB
testcase_53 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

constexpr int E = 30;

struct Tree {
  Tree *l, *r;
  int e;
  int sum;
  Tree(int e) : l(nullptr), r(nullptr), e(e), sum(0) {}
  void insert(int x) {
    if (e == 0) {
      sum = 1;
    } else {
      if (x & 1 << (e - 1)) {
        if (!r) r = new Tree(e - 1);
        r->insert(x);
      } else {
        if (!l) l = new Tree(e - 1);
        l->insert(x);
      }
      sum = (l ? l->sum : 0) + (r ? r->sum : 0);
    }
  }
};

int N;
int ASum[2010];

int main() {
  for (; ~scanf("%d", &N); ) {
    for (int i = 0; i < N; ++i) {
      long long a;
      scanf("%lld", &a);
      ASum[i + 1] = ASum[i] ^ a;
    }
    int d = 0;
    Tree *t = new Tree(E);
    t->insert(ASum[N]);
    for (int i = N; i--; ) {
      d = 0;
      Tree *u = t;
      for (int e = E; e-- && u; ) {
        if (ASum[i] & 1 << e) {
          if ((u->r ? u->r->sum : 0) == 1 << e) {
            d |= 1 << e;
            u = u->l;
          } else {
            u = u->r;
          }
        } else {
          if ((u->l ? u->l->sum : 0) == 1 << e) {
            d |= 1 << e;
            u = u->r;
          } else {
            u = u->l;
          }
        }
      }
      t->insert(ASum[i] ^ d);
    }
    puts(d ? "Takahashi" : "Takanashi");
  }
  return 0;
}
0