#P15282. [MCO 2024] Escape
[MCO 2024] Escape
Description
:::epigraph After dealing with numbers, Evirir the dragon is too tired and he decides to play a video game. :::
Evirir the dragon is playing a video game named !
The game takes place on a grid with rows and columns. The rows are numbered from top to bottom and the columns are numbered from left to right. The cell on row and column is denoted by . Two different cells are if they share a side (so each cell is adjacent to at most 4 cells: up, down, left, and right). Formally, cell is adjacent to , , , and (if they exist).
Each cell in the grid is one of the four types below, and each cell type is represented by a character:
.denotes an empty cellddenotes a cell with a dogedenotes an escape door#denotes a wall cell
Evirir wants to reach an escape door and avoid dogs. Initially, Evirir has (health points) and is on a non-wall cell. Every second, the following happens in order:
- If Evirir has less than or equal to 0 HP, then he loses the game immediately.
- If Evirir is at an escape door (and has at least 1 HP), then he wins the game immediately.
- Evirir does not move or moves to an adjacent cell that is a wall cell.
- Then, every dog does not move or moves to an adjacent cell that is a wall cell. Multiple dogs can move to the same cell.
- Then, for every dog in the same cell as Evirir, the dog bites Evirir and Evirir's HP decreases by 1. Then, the dog disappears from the grid forever.
Furthermore, $\textbf{before starting the game, Evirir must first decide the sequence of cells he will move to}$. That is, Evirir must fix his moves without knowing the dogs' moves. The dogs may then look at Evirir's plan and move accordingly.
We call a cell if and only if it is not a wall cell and Evirir can win if he starts at the cell, moves according to his plan, and wins . Note that Evirir can start at escape gates or on a cell with a dog.
Since Evirir the dragon is lazy, he asks you to determine the number of winning cells in the grid.
Input Format
The first line consists of two integers, and ().
Then, lines follow, describing the grid cells. Each line consists of characters. The -th character in line denotes the cell type of cell .
Output Format
Print one integer, the number of cells.
4 5
...d.
.e#e.
..d#d
.e.d.
14
Hint
Note
Let us say we are starting at cell and our path is shown below.
:::align{center}
:::
here shows the path that is chosen.
With this, the dog at remains stationary and dog at goes downwards immediately after the player makes the first move.
Before the game starts, player has HP at is currently at .
:::align{center}
:::
shows the position of the player.
Now he moves to the left, there is a dog at cell , so he has only HP remaining. At the same time the dog at cell moves down and the grid now looks like this:
:::align{center}
:::
It is obvious that the player will lose at the next move, immediately after the player moves to the left. It can be observed that cell is not a winning cell after considering all possibilities of routes.
Scoring
Subtask 1 (11 points): There is at most one dog on the grid.
Subtask 2 (13 points):
Subtask 3 (15 points):
Subtask 4 (15 points):
Subtask 5 (17 points): There is at most one escape door.
Subtask 6 (19 points):
Subtask 7 (10 points): No other constraints.
京公网安备 11011102002149号