Codeforces Round 1102 (Div. 2)
G
条带、令牌与两名玩家
Stripe, Token and Two Players
Codeforces
2700
原题
← F→

条带、令牌与两名玩家AI (CI翻译)

There is a stripe of $n + 1$ cells, numbered from $1$ to $n + 1$. Initially, there is a token with power $1$ on cell number $1$, and the numbers $a_1, a_2, \ldots, a_n$ are written on cells $1, 2, \ldots, n$ respectively.

翻译中…

Two players play a game. On each move, the player performs the following actions in order:

翻译中…
  1. Suppose the token is on cell number $i$.
  2. The player may increase the power of the token by any integer from $0$ to $a_i$ inclusive.
  3. Then the player moves the token forward by any positive integer not exceeding the token's power, such that after this action the token does not leave the stripe.
翻译中…

The player after whose move the token lands on cell $n + 1$ wins.

翻译中…

Who wins with optimal play?

翻译中…

Input

输入格式

AI (CI翻译)

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

每个测试包含多个测试用例。第一行包含测试用例数量 $t$($1 \le t \le 10^4$)。接下来是各个测试用例的描述。AI (CI翻译)

The first line of each test case contains one integer $n$ ($1 \le n \le 10^5$) — the number of written numbers.

每个测试用例的第一行包含一个整数 $n$($1 \le n \le 10^5$),表示写在格子上的数字数量。AI (CI翻译)

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$) — the numbers written on the cells.

第二行包含 $n$ 个整数 $a_1, a_2, \ldots, a_n$($0 \le a_i \le 10^9$),表示写在各个格子上的数字。AI (CI翻译)

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

保证所有测试用例中 $n$ 的总和不超过 $10^5$。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, output one integer, $1$ or $2$ — the number of the player who wins with optimal play. (Player $1$ makes the first move.)

对于每个测试用例,输出一个整数 $1$ 或 $2$,表示在双方采取最优策略时获胜的玩家编号。(玩家 $1$ 先手。)AI (CI翻译)

Note

说明

AI (CI翻译)

In the first test case, the power of the token remains equal to $1$ throughout the game, so on every move the players must move exactly one cell forward. Thus, $3$ moves will be made, and the last move will be made by player $1$, so he will win in any case.

在第一个测试用例中,令牌的力量在整个游戏过程中始终保持为 $1$,因此每次移动时玩家都必须恰好向前移动一个格子。因此,总共会进行 $3$ 次移动,最后一次移动由玩家 $1$ 完成,所以无论如何他都会获胜。AI (CI翻译)

In the second test case, player $2$ has a winning strategy: on their very first move, increase the token's power as much as possible, and then jump to cell $4$ and win. This is always possible, since at the start of the move the token will be on cell $2$ or $3$, and its power can be increased to at least $2$.

在第二个测试用例中,玩家 $2$ 存在一种获胜策略:在自己的第一次移动中,将令牌的力量尽可能增加,然后跳到格子 $4$ 并获胜。这始终是可行的,因为在该次移动开始时,令牌位于格子 $2$ 或 $3$,并且其力量可以增加到至少 $2$。AI (CI翻译)

样例

Input #1
4
3
0 0 0
3
1 1 2
5
0 0 1 0 0
9
0 1 2 0 0 1 0 0 0
Output #1
1
2
1
2
InputCopy OutputCopy
题目信息
题号
2234G
时间限制
3 s
内存限制
256 MB
标签
数据结构
动态规划
博弈论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。