K. King of Maze

Codeforces
IDCF10282K
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Fish is extremely good at maze game and he becomes king of maze. This time he turns to build a tricky maze game and invite Ruins to solve. The maze can be simply treated as a $N times M$ gird, and some cells inside are walls where one can not move into. In this game, Ruins starts from one cell and he can move into any four-connected neighbor cells if empty. The length of a path in the maze is defined as the number of moves he have to do from the start to the end and his goal is to escape from the maze. As he is a smart guy, he always uses the shortest path strategy: he will always choose the shortest path from current cell to the exit, and moves to the next cell in this path. If there are multiple cells available, he will consider the cell in the top $(x -1, y)$, underneath $(x + 1, y)$, in the left $(x, y -1)$, in the right $(x, y + 1)$ in order and moves to the available one (in one of shortest path) if he is currently in $(x, y)$. Fish's maze is a little different: besides the exit, walls and empty cells in all maze games, there is a different kind of cells: lift, which is controllable so that he can change cell of this kind into empty cell or into wall every time he wants. To make this game more interesting, before Ruins's next move, Fish will change some lift cells (or none) into walls and let the remainders become empty cells and wait for Ruins's decision. Of course, if Ruins is standing on a lift cell, Fish can not change this cell into wall. Just help Fish to find a strategy to trap Ruins in the maze as long as possible! The first line of input contains an integer $T$, representing the number of test cases. Then for each test case: The first line contains three integers $N, M, Q$, representing the number of rows of the maze, the number of columns of the maze and the number of start cells you have to deal with. Then $N$ lines follow, the $i$-th line containing a string of length $M$ representing a row in the maze, the $j$-th of which represents the cell of $(i, j)$ . In the maze, "$sans(.)$" represents empty cell, "$sans(#)$" represents wall, "$sans(?)$" represents lift cell and "$sans(E)$" represent the exit. It is guaranteed that there is exactly one "$sans(E)$" in a maze. Then $Q$ lines follow, each line containing two integers $x, y$ which is the start cell of Ruins in one game for given maze, the start cell will never be a wall. For each test case, you should output *Case $x$:* first, where $x$ indicates the case number starting from $1$. Then $Q$ lines follow, each line containing one integer representing the longest time you can trap Ruins in the maze for the given start cell. If you can trap him forever, output *-1*. $1 <= T <= 100$ $1 <= N, M <= 50$ Denote the number of "$sans(?)$" in a maze as $K$, $0 <= K <= 10$ $1 <= Q <= N times M$ $1 <= x <= N$ $1 <= y <= M$ For $90 %$ test cases: $max (N, M) <= 10$ ## Input The first line of input contains an integer $T$, representing the number of test cases.Then for each test case:The first line contains three integers $N, M, Q$, representing the number of rows of the maze, the number of columns of the maze and the number of start cells you have to deal with.Then $N$ lines follow, the $i$-th line containing a string of length $M$ representing a row in the maze, the $j$-th of which represents the cell of $(i, j)$ . In the maze, "$sans(.)$" represents empty cell, "$sans(#)$" represents wall, "$sans(?)$" represents lift cell and "$sans(E)$" represent the exit. It is guaranteed that there is exactly one "$sans(E)$" in a maze.Then $Q$ lines follow, each line containing two integers $x, y$ which is the start cell of Ruins in one game for given maze, the start cell will never be a wall. ## Output For each test case, you should output *Case $x$:* first, where $x$ indicates the case number starting from $1$. Then $Q$ lines follow, each line containing one integer representing the longest time you can trap Ruins in the maze for the given start cell. If you can trap him forever, output *-1*. [samples] ## Note $1 <= T <= 100$$1 <= N, M <= 50$Denote the number of "$sans(?)$" in a maze as $K$, $0 <= K <= 10$$1 <= Q <= N times M$$1 <= x <= N$$1 <= y <= M$For $90 %$ test cases: $max (N, M) <= 10$
**Definitions** Let $ N \in \mathbb{Z}^+ $ with $ 1 \leq N \leq 300 $. Let $ P = \{p_1, p_2, \dots, p_N\} \subset \mathbb{Z}^2 $ be a set of $ N $ distinct lattice points in the plane, with no three collinear. Let $ \mathcal{S} = \mathcal{P}(P) $ be the power set of $ P $, i.e., the set of all subsets of $ P $. For any subset $ S \subseteq P $, let $ \text{conv}(S) $ denote the convex hull of $ S $, and let $ h(S) = |\text{conv}(S)| $ be the number of points in $ S $ that lie on the boundary of the convex hull (i.e., the vertices of the convex hull). By definition: - If $ |S| \leq 2 $, then $ h(S) = |S| $. - If $ |S| \geq 3 $, then $ h(S) $ is the number of points in $ S $ that are vertices of the convex hull of $ S $. **Constraints** 1. $ 1 \leq N \leq 300 $ 2. For all $ p_i = (x_i, y_i) \in P $, $ 0 \leq x_i, y_i \leq 10^6 $ 3. No three points in $ P $ are collinear. **Objective** Compute: $$ \sum_{S \subseteq P} h(S) \mod (10^9 + 7) $$
API Response (JSON)
{
  "problem": {
    "name": "K. King of Maze",
    "description": {
      "content": "Fish is extremely good at maze game and he becomes king of maze. This time he turns to build a tricky maze game and invite Ruins to solve. The maze can be simply treated as a $N times M$ gird, and so",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10282K"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Fish is extremely good at maze game and he becomes king of maze. This time he turns to build a tricky maze game and invite Ruins to solve.\n\nThe maze can be simply treated as a $N times M$ gird, and so...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ N \\in \\mathbb{Z}^+ $ with $ 1 \\leq N \\leq 300 $.  \nLet $ P = \\{p_1, p_2, \\dots, p_N\\} \\subset \\mathbb{Z}^2 $ be a set of $ N $ distinct lattice points in the plane, with no thr...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments