L. River Game

Codeforces
IDCF10250L
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
In order to kill time, you devised a little game. The wetland is represented by an $N times N$ grid made of 3 types of squares: firm ground, wet zone, and protected zone. Connected wet zone squares form wet areas, which are maximal sets of wet zone squares such that we can go from any square of the area to any other square of the area by a path of connected wet zone squares. Two squares are considered connected when they share one edge, so that squares not on the border of the grid are connected to 4 other squares. Each wet area must be connected to both the left and right sides of the grid, and does not contain more than $2 N$ wet zone squares. Two wet zone squares that belong to two different wet areas will always be at distance at least 3 from each other, the distance being counted by moving horizontally or vertically on the grid. For example, in the two examples below, the blue squares are at distance 3 from one another. One after the other, you and your friend will each take turns placing a camera on the wetland with the following constraints: The first player who cannot place a camera anymore loses the game. Assuming both players play optimally, will the first player win or lose? The input consists of the following lines: *Limits* The input satisfies $1 <= N <= 10$. The four words "First player will win" if the first player wins the game provided both players play optimally, or "Second player will win" otherwise. *Sample Explanation 1* The first player can place a camera in three possible places: if he places a camera in the left or right position, then the second player can place one in the other position and wins the game. On the other hand, if the first player places a camera in the middle, the second player cannot place another camera and loses. ## Input The input consists of the following lines: on the first line, the integer $N$; on the next $N$ lines, a string representing a row of the grid: "*" represents a wet zone square, "." represents a firm ground square and "x" represents a protected square. *Limits*The input satisfies $1 <= N <= 10$. ## Output The four words "First player will win" if the first player wins the game provided both players play optimally, or "Second player will win" otherwise. [samples] ## Note *Sample Explanation 1*The first player can place a camera in three possible places: if he places a camera in the left or right position, then the second player can place one in the other position and wins the game. On the other hand, if the first player places a camera in the middle, the second player cannot place another camera and loses.
**Definitions** Let $ n, m \in \mathbb{Z}^+ $ denote the number of boxes and number of moves, respectively. Let $ A = (A_1, A_2, \dots, A_n) \in \mathbb{Z}^n $ be the initial number of balls in each box. Let $ S = (S_1, S_2, \dots, S_n) \in \{0,1\}^n $ be the initial state of each box, where $ S_i = 1 $ if box $ i $ is open, $ 0 $ if closed. Let $ M = (m_1, m_2, \dots, m_m) $ be a sequence of $ m $ moves, each of type: - **turon**: $ (L, R) $ — flip the state $ S_i \leftarrow 1 - S_i $ for all $ i \in [L, R] $. - **puto**: $ (L, R, v) $ — add $ v $ to $ A_i $ for all $ i \in [L, R] $ where $ S_i = 1 $. - **taho**: $ (L, R) $ — compute $ \sum_{i=L}^{R} A_i \cdot S_i $. **Constraints** 1. $ 1 \le n, m \le 3 \cdot 10^5 $ 2. $ 1 \le A_i, v \le 10^6 $ 3. $ 1 \le L \le R \le n $ for all moves 4. $ S_i \in \{0,1\} $ for all $ i $, updated dynamically **Objective** For each taho move $ (L, R) $, output: $$ \sum_{i=L}^{R} A_i \cdot S_i $$
API Response (JSON)
{
  "problem": {
    "name": "L. River Game",
    "description": {
      "content": "In order to kill time, you devised a little game. The wetland is represented by an $N times N$ grid made of 3 types of squares: firm ground, wet zone, and protected zone. Connected wet zone squares f",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10250L"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "In order to kill time, you devised a little game. The wetland is represented by an $N times N$ grid made of 3 types of squares: firm ground, wet zone, and protected zone.\n\nConnected wet zone squares f...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n, m \\in \\mathbb{Z}^+ $ denote the number of boxes and number of moves, respectively.  \nLet $ A = (A_1, A_2, \\dots, A_n) \\in \\mathbb{Z}^n $ be the initial number of balls in ea...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments