CF2115D.Gellyfish and Forget-Me-Not
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Gellyfish and Flower are playing a game.
The game consists of two arrays of n integers a1,a2,…,an and b1,b2,…,bn, along with a binary string c1c2…cn of length n.
There is also an integer x which is initialized to 0.
The game consists of n rounds. For i=1,2,…,n, the round proceeds as follows:
- If ci=0, Gellyfish will be the active player. Otherwise, if ci=1, Flower will be the active player.
- The active player will perform exactly one of the following operations:
- Set x:=x⊕ai.
- Set x:=x⊕bi.
Here, ⊕ denotes the bitwise XOR operation.
Gellyfish wants to minimize the final value of $ x $ after $ n $ rounds, while Flower wants to maximize it.
Find the final value of $ x $ after all $ n $ rounds if both players play optimally.
水母和花朵正在玩一个游戏。
游戏包含两个长度为 n 的整数数组 a1,a2,…,an 和 b1,b2,…,bn,以及一个长度为 n 的二进制字符串 c1c2…cn。
此外还有一个整数 x,初始值为 0。
游戏共进行 n 轮。对 i=1,2,…,n,第 i 轮按如下方式进行:
- 若 ci=0,则水母为当前活跃玩家;若 ci=1,则花朵为当前活跃玩家。
- 当前活跃玩家恰好执行以下操作之一:
- 将 x 更新为 x:=x⊕ai;
- 将 x 更新为 x:=x⊕bi。
其中,⊕ 表示按位异或运算。
水母希望在 n 轮结束后使 x 的最终值尽可能小,而花朵希望使其尽可能大。
若双方均采取最优策略,求 n 轮结束后 x 的最终值。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains a single integer n (1≤n≤105) — the number of rounds of the game.
The second line of each test case contains n integers a1,a2,…,an (0≤ai<260).
The third line of each test case contains n integers b1,b2,…,bn (0≤bi<260).
The fourth line of each test case contains a binary string c of length n.
It is guaranteed that the sum of n over all test cases does not exceed 105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤105)—— 表示游戏的轮数。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(0≤ai<260)。
每个测试用例的第三行包含 n 个整数 b1,b2,…,bn(0≤bi<260)。
每个测试用例的第四行包含一个长度为 n 的二进制字符串 c。
保证所有测试用例的 n 值之和不超过 105。
输出格式
For each test case, output a single integer — the final value of $ x $ after all $ n $ rounds.
对于每个测试用例,输出一个整数——经过全部 $ n $ 轮操作后 $ x $ 的最终值。
输入输出样例
输入#1
5 1 0 2 0 2 12 2 13 3 11 3 6 1 2 6 2 3 010 4 1 12 7 2 4 14 4 2 0111 9 0 5 10 6 6 2 6 2 11 7 3 15 3 6 7 6 7 8 110010010
输出#1
0 15 6 11 5
说明/提示
In the first test case, there's only one round and Gellyfish is the active player of that round. Therefore, she will choose a1, and the final value of x is 0.
In the second test case, Flower will be the active player in both rounds. She will choose a1 and b2, and the final value of x is a1⊕b2=15. Flower may also choose b1 and a2 instead for the same result of x=a2⊕b1=15.
In the third test case, a1=b1 so it doesn't matter what decision Gellyfish makes in the first round. In the second round:
- If Flower chooses a2, then x will become 7. Gellyfish will choose b3 in the third round, so the final value of x will be 4.
- Otherwise, Flower chooses b2, then x will become 4. Gellyfish will choose a3 in the third round, so the final value of x will be 6.
Flower wants to maximize the final value of x, so Flower will choose b2 in the second round. Therefore, the final value of x will be 6.
在第一个测试用例中,仅有一轮,且 Gellyfish 是该轮的活跃玩家。因此,她将选择 a1,最终 x 的值为 0。
在第二个测试用例中,Flower 将在两轮中均为活跃玩家。她将选择 a1 和 b2,最终 x 的值为 a1⊕b2=15。Flower 也可改为选择 b1 和 a2,此时同样得到 x=a2⊕b1=15。
在第三个测试用例中,a1=b1,因此 Gellyfish 在第一轮中的选择无关紧要。在第二轮中:
- 若 Flower 选择 a2,则 x 将变为 7;Gellyfish 在第三轮中将选择 b3,因此 x 的最终值为 4。
- 否则,Flower 选择 b2,则 x 将变为 4;Gellyfish 在第三轮中将选择 a3,因此 x 的最终值为 6。
Flower 希望最大化 x 的最终值,因此她在第二轮中会选择 b2。故 x 的最终值为 6。
输入解题思路,AI测评打分。不知道怎么写?