Skip to content

Commit de1c624

Browse files
post : agc045a
1 parent 18a729f commit de1c624

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

_posts/2025-01-08-agc045-a.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: 【精進5】AGC045-A
3+
date: 2025-1-08 17:12:00 0900
4+
categories: [競技プログラミング]
5+
tags: [AtCoder,AGC,精進,XOR]
6+
math : true
7+
---
8+
[前の精進](https://yokoyama-midori.github.io/posts/abc283-g/)つながりで$\mathrm{xor}$の問題。後ろから考える。
9+
## 問題
10+
[A - Xor Battle](https://atcoder.jp/contests/agc045/tasks/agc045_a)
11+
人$0$と人$1$がゲームをする。変数$x=0$とし$i$回目のラウンドで人$S_i$はなにもしないか$x \gets x\oplus A_i$とするかを選択する。最終的に人$0$は$x=0$を、人$1$は$x\ne 0$を目指すとき達成するのはどちらか?
12+
13+
## 解法
14+
たいていのケースで人$1$が有利なルールに見えるため人$0$が勝つのがどのようなケースなのかを考察する。後ろから考えていく。$i=N$で$S_i=1$ならばその時点での$x$に対し、$x,x\oplus A_i$の少なくとも一方が$0$でないため人$0$は負ける。$S_i=0$の場合、$x\in\lbrace 0,A_i\rbrace$なら人$0$は勝つ。同様にある$i+1$で$x\in U$ならば人$0$が勝つ場合、$i$での勝利条件がどうなるかを考える。 $S_i=1$の場合、条件は$A_i \in U$かつ$x\in U$である。$S_i=0$の場合条件は$x\in U \cup \lbrace y\oplus A_i | y\in U \rbrace$である。これらの考察から人$0$の勝利条件は次のようになることが分かる。
15+
16+
> $\lbrace A_{i+1},\dots,A_N \rbrace$が張る空間に$A_i$が含まれないならば$S_i = 0$である。
17+
18+
この判定は前回の解説と[同様の方法](https://x.com/noshi91/status/1200702280128856064)でできる。
19+
```cpp
20+
#include "template.hpp"
21+
void solve() {
22+
LL(n);
23+
vl a(n);
24+
input(a);
25+
STR(s);
26+
vl basis;
27+
auto in = [&basis](ll num) -> bool {
28+
for(auto e : basis)
29+
chmin(num, e ^ num);
30+
if(num) {
31+
basis.push_back(num);
32+
return true;
33+
}
34+
return false;
35+
};
36+
for(int i = n - 1; i >= 0; i--) {
37+
bool flag = in(a[i]);
38+
if(s[i] == '1' and flag) {
39+
print(1);
40+
return;
41+
}
42+
}
43+
print(0);
44+
}
45+
46+
int main() {
47+
ios::sync_with_stdio(false);
48+
std::cin.tie(nullptr);
49+
cout << std::setprecision(16);
50+
int t = 1;
51+
cin >> t;
52+
rep(_, t) {
53+
solve();
54+
}
55+
}
56+
57+
```

0 commit comments

Comments
 (0)