QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#12304. 选择你自己的 Nim 游戏

Statistics

Alice 和 Bob 非常喜欢玩 Nim 游戏(如果你不记得规则,请参考“说明”部分)。 他们玩了太多次,以至于一眼就能看出胜负:如果有 $a_1, \dots, a_n$ 个石子的堆,当且仅当它们的按位异或和 $a_1 \oplus \dots \oplus a_n$ 不为零时,先手必胜。

他们听说在某些网络游戏中,玩家在游戏开始前可以选择角色,这增加了一层策略性。为什么不在 Nim 游戏中也这样做呢?

他们想出了以下版本。Alice 和 Bob 各自拥有几个装有石子堆的盒子。在第一阶段,他们从每个盒子中恰好选出一个石子堆。在第二阶段,Alice 从这些选出的石子堆中选择一个非空子集,然后以这些石子堆进行常规的 Nim 游戏,由 Bob 先手。

Bob 已经知道了 Alice 选出的石子堆。请帮助他进行选择,使得无论 Alice 在第二阶段选择哪一个子集,Bob 都能获胜。

输入格式

第一行包含一个整数 $n$ ($0 \le n \le 60$),表示 Alice 选出的石子堆数量。 如果 $n > 0$,下一行包含 $n$ 个整数:这些石子堆的大小。否则,省略该行。 下一行包含一个整数 $m$ ($1 \le m \le 60$),表示 Bob 的盒子数量。 接下来的 $m$ 行,每行包含一个盒子的描述。每个描述以一个数字 $k_i$ ($1 \le k_i \le 5000$) 开头,表示该盒子中石子堆的数量。随后是 $k_i$ 个数字,表示这些石子堆的大小。 每个石子堆的大小在 $1$ 到 $2^{60} - 1$ 之间(包含边界)。Bob 的盒子中石子堆的总数不超过 $5000$。

输出格式

如果 Bob 无法获胜(即无论他如何选择,Alice 总能做出某种选择使得最终的 Nim 局面为必败态),输出 “-1”(不含引号)。否则,输出 $m$ 个整数:Bob 应从他的每个盒子中选出的石子堆大小,顺序与输入中盒子的顺序一致。

样例

样例输入 1

2
1 2
2
2 1 2
3 1 2 3

样例输出 1

-1

样例输入 2

1
5
2
3 1 2 3
4 4 5 6 7

样例输出 2

1
6

说明

在 Nim 游戏中,有若干堆石子。每一轮,玩家选择任意一堆并取走正整数个石子。取走最后一个石子的玩家获胜。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#520Editorial Open集训队作业 解题报告 by 刘家炜Qingyu2026-01-02 21:38:06 Download
#357EditorialOpen题解jiangly2025-12-14 07:16:42View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.