ARC087E 题解
DaiRuiChen007 · · 题解
Problem Link
题目大意
定义一个 01 串集合
S 是好的:
- 所有元素长度在
[1,m] 之间。- 对于所有
s\in S ,s 的所有前缀不属于S 。给定初始值
S=S_0 ,Alice 和 Bob 轮流往S 中插入一个字符串,谁不能保持S 是好的就输了,求赢家。数据范围:
L=\sum_{s\in S} |s|\le 10^5,m\le 10^{18} 。
思路分析
先建立 Trie 树,那么 Trie 上的点和所有叶子的子树不能选。
那么剩下来的就是一些一度点的空子树,显然这些子树之间的博弈是互不影响的,求出每个子树的 SG 值后异或起来即可。
我们只要求
打表发现
时间复杂度
代码呈现
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=1e5+5;
int n,tr[MAXN][2],tot=1; ll m,ans=0;
ll lowbit(ll x) { return x&-x; }
void dfs(int u,int d) {
if(d==m) return ;
for(int k:{0,1}) {
if(tr[u][k]) dfs(tr[u][k],d+1);
else ans^=lowbit(m-d);
}
}
signed main() {
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=1;i<=n;++i) {
string str; cin>>str; int p=1;
for(char c:str) {
if(!tr[p][c-'0']) tr[p][c-'0']=++tot;
p=tr[p][c-'0'];
}
}
dfs(1,0);
cout<<(ans?"Alice":"Bob")<<"\n";
return 0;
}