B. Godsend

Codeforces
IDCF841B
Time2000ms
Memory256MB
Difficulty
gamesmath
English · Original
Chinese · Translation
Formal · Original
Leha somehow found an array consisting of _n_ integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an odd sum of numbers and remove it from the array, after that the remaining parts are glued together into one array and the game continues. The second player can choose a subsegment of non-zero length with an even sum and remove it. Loses the one who can not make a move. Who will win if both play optimally? ## Input First line of input data contains single integer _n_ (1 ≤ _n_ ≤ 106) — length of the array. Next line contains _n_ integers _a_1, _a_2, ..., _a__n_ (0 ≤ _a__i_ ≤ 109). ## Output Output answer in single line. "_First_", if first player wins, and "_Second_" otherwise (without quotes). [samples] ## Note In first sample first player remove whole array in one move and win. In second sample first player can't make a move and lose.
Leha 找到了一个包含 #cf_span[n] 个整数的数组。观察这个数组后,他提出了一个问题:两名玩家在该数组上进行游戏。玩家轮流行动。先手玩家可以选择一个非空子段,其元素的交错和为奇数,并将其从数组中移除,随后剩余部分拼接成一个新数组,游戏继续。后手玩家可以选择一个非空子段,其元素的交错和为偶数,并将其移除。无法行动的玩家输。若双方均采取最优策略,谁会获胜? 输入数据的第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 106]) —— 数组的长度。 第二行包含 #cf_span[n] 个整数 #cf_span[a1, a2, ..., an] (#cf_span[0 ≤ ai ≤ 109])。 请在一行中输出答案:若先手玩家获胜,输出 "_First_",否则输出 "_Second_"(不含引号)。 在第一个样例中,先手玩家一步移除整个数组并获胜。 在第二个样例中,先手玩家无法行动,因此失败。 ## Input 输入数据的第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 106]) —— 数组的长度。第二行包含 #cf_span[n] 个整数 #cf_span[a1, a2, ..., an] (#cf_span[0 ≤ ai ≤ 109])。 ## Output 请在一行中输出答案:若先手玩家获胜,输出 "_First_",否则输出 "_Second_"(不含引号)。 [samples] ## Note 在第一个样例中,先手玩家一步移除整个数组并获胜。在第二个样例中,先手玩家无法行动,因此失败。
**Definitions** Let $ n \in \mathbb{Z}^+ $ be the length of the array. Let $ A = (a_1, a_2, \dots, a_n) $ be a sequence of non-negative integers, $ a_i \in \mathbb{Z}_{\geq 0} $. **Game Rules** - Two players alternate turns, starting with Player 1. - Player 1 may remove any contiguous subsegment of positive length whose **sum is odd**. - Player 2 may remove any contiguous subsegment of positive length whose **sum is even**. - After removal, the remaining parts are concatenated. - A player who cannot make a valid move loses. **Objective** Determine the winner under optimal play. **Key Invariant** Let $ s = \sum_{i=1}^n a_i $ be the total sum of the array. Let $ p $ be the number of **odd** elements in $ A $. **Observation** - The parity of the total sum $ s $ determines the initial move availability: - If $ s $ is **odd**, Player 1 can remove the entire array and win immediately. - If $ s $ is **even**, then the game depends on the existence of any odd-length subsegment with odd sum (for Player 1) or even-length subsegment with even sum (for Player 2). - Crucially, **Player 1 can move if and only if there exists at least one odd element** in $ A $. - Because: Any single odd element forms a subsegment of odd sum. - If all elements are even, then every subsegment has even sum → Player 1 cannot move → loses. - If Player 1 can move, then **after any valid move**, the parity of the total sum flips (odd → even or even → odd), and the game reduces. - However, since Player 1 can always remove a single odd element (if one exists), and this reduces the array, the game becomes a **parity game on the count of odd elements**. **Critical Insight** - Player 1 wins **if and only if** there is **at least one odd number** in the array. - Because: - If $ p \geq 1 $, Player 1 removes one odd element → array sum flips parity. - Player 2 is now faced with an array of total sum odd → but Player 2 can only remove even-sum segments. - However, Player 2 may still have moves (e.g., removing two even numbers). - But **the key is**: As long as there is **any odd element**, Player 1 can always respond by removing one odd element, and eventually force Player 2 into a position with no even-sum moves. - Actually, a deeper known result in such impartial-like games (though not impartial, since moves differ) shows: > **Player 1 wins if and only if the array contains at least one odd number.** > **Player 2 wins if and only if all numbers are even.** **Final Formal Objective** Let $ p = \left| \{ i \in \{1, \dots, n\} \mid a_i \text{ is odd} \} \right| $. Then: $$ \text{Winner} = \begin{cases} \text{First} & \text{if } p \geq 1 \\ \text{Second} & \text{if } p = 0 \end{cases} $$
Samples
Input #1
4
1 3 2 3
Output #1
First
Input #2
2
2 2
Output #2
Second
API Response (JSON)
{
  "problem": {
    "name": "B. Godsend",
    "description": {
      "content": "Leha somehow found an array consisting of _n_ integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF841B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Leha somehow found an array consisting of _n_ integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Leha 找到了一个包含 #cf_span[n] 个整数的数组。观察这个数组后,他提出了一个问题:两名玩家在该数组上进行游戏。玩家轮流行动。先手玩家可以选择一个非空子段,其元素的交错和为奇数,并将其从数组中移除,随后剩余部分拼接成一个新数组,游戏继续。后手玩家可以选择一个非空子段,其元素的交错和为偶数,并将其移除。无法行动的玩家输。若双方均采取最优策略,谁会获胜?\n\n输入数据的第一行包含一个整数 ...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the length of the array.  \nLet $ A = (a_1, a_2, \\dots, a_n) $ be a sequence of non-negative integers, $ a_i \\in \\mathbb{Z}_{\\geq 0} $.  \n\n**Game Rules**...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments