QOJ.ac

QOJ

時間限制: 15 s 記憶體限制: 256 MB 總分: 100

#12263. 游戏

统计

考虑以下双人游戏。初始时有一个数字序列。随后玩家轮流移除序列的第一个或最后一个元素。如果在某次移动后,序列变成了若干个终止序列之一,则游戏结束,最后进行移动的玩家获胜。如果没有任何玩家可以进行移动(因为序列长度为 0),则没有玩家获胜。确定该游戏中哪位玩家拥有必胜策略。

输入的第一行包含测试用例的数量 $z$。接下来是各测试用例的描述。

每个测试用例的第一行包含一个整数 $n$ ($1 \le n \le 10^6$),随后是 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^9$),即初始序列。第二行包含一个整数 $k$,表示终止序列的数量。接下来的 $k$ 行包含终止序列的描述。每一行包含一个整数 $m$ ($m \ge 1$),表示序列的长度,随后是序列的 $m$ 个元素:$w_1, w_2, \dots, w_m$ ($0 \le w_i \le 10^9$)。所有终止序列的总长度不超过 $3 \cdot 10^6$。

连续的测试用例之间由一个空行分隔。

对于每个测试用例,如果先手玩家获胜,输出 “FIRST”;如果后手玩家获胜,输出 “SECOND”;如果无人获胜,输出 “DRAW”。

样例

输入 1

1
5 1 1 2 2 1
4
1 2
3 1 2 2
2 2 1
2 1 1

输出 1

SECOND

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.