結果
問題 | No.946 箱箱箱 |
ユーザー |
👑 |
提出日時 | 2019-12-09 03:44:54 |
言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 1,261 bytes |
コンパイル時間 | 184 ms |
コンパイル使用メモリ | 104,448 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-30 15:56:34 |
合計ジャッジ時間 | 1,832 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 51 |
ソースコード
#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;}