#P1288. 取数游戏 II
取数游戏 II
Description
There is a number-picking game. Initially, you are given a ring; each edge on the ring has a non-negative integer on it. Among these integers, at least one is . Then, a coin is placed on a node of the ring. Starting from this node, two players take turns according to the following rules:
- Choose one of the two edges adjacent to the coin (left or right), and its number must be non-zero.
- Decrease the number on that edge to any non-negative integer (it must strictly decrease).
- Move the coin to the other endpoint of that edge.
If it is a player's turn and the numbers on both edges adjacent to the coin are , then that player loses.
As shown below is a sequence of moves between Alice and Bob (the black node marks the coin's position).

The results of the panels are:
- : Alice to move.
- : Bob to move.
- : Alice to move.
- : Bob to move.
In , when it is Bob's turn, both adjacent edges have number , so Alice wins.
Your task is to determine, given the ring, the edge values, and the starting node (the coin's position), whether the first player has a forced winning strategy.
Input Format
The first line contains an integer , the number of nodes on the ring.
The second line contains integers, each not exceeding , giving the values on the edges in order. The coin initially sits on the node between the first edge and the last edge.
Output Format
Output a single line. If there exists a winning strategy, output YES, otherwise output NO.
4
2 5 3 0
YES
3
0 0 0
NO
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号