线性基好题。
考虑从后往前枚举,设 表示前 步做完后 必胜的 集合。
那么当 时, 相当于 并上 中所有数与 的异或值,即 。而当 时, 且 。
根据 的性质,发现 是所有 的 取若干个异或得到的数的集合,并且若 ,则 ,所以当 时,如果 ,则所有 ,即 。而当 时,对于任意的 , 和 不可能同时在集合里(由上面性质),所以 ,即 获胜。
我们可以维护集合 的线性基,这样插入和查询是否 都很方便。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 2e9;
inline ll read() {
ll s = 0,f = 1;char ch = getchar();
while (!isdigit(ch)) f = ch == '-' ? -1 : 1, ch = getchar();
while (isdigit(ch)) s = (s << 3) + (s << 1) + ch - '0', ch = getchar();
return s*f;
}
ll a[210];
struct Linear_Basis {
ll p[65];
bool ins(ll x) {
for (int i = 62;~i;i -- ) {
if (!(x >> i & 1)) continue;
if (!p[i]) {
p[i] = x;
return 1;
}
x ^= p[i];
}
return 0;
}
}L;
char s[210];
int main() {
int T = read();
while (T -- ) {
int n = read();
for (int i = 1;i <= n;i ++ ) a[i] = read();
scanf("%s",s+1);
for (int i = 0;i <= 62;i ++ ) L.p[i] = 0;
for (int i = n;i;i -- ) {
if (L.ins(a[i]) && s[i] == '1') {
puts("1");
goto bre;
}
}
puts("0");
bre:;
}
return 0;
}