#P3786. 萃香抱西瓜
萃香抱西瓜
Description
Suika’s environment is simplified to a grid of length and width . The -coordinate range is , and the -coordinate range is .
At the initial moment (time ), she stands on the cell at coordinates .
A watermelon may appear on any cell. At each time unit, it may move in any direction or stay still. The positions and trajectories of all watermelons are known. The total number of watermelons is , but only of them can be picked up by Suika; the others are too big and may hurt her.
The whole process lasts for time steps. Suika wants to pick up all small watermelons while avoiding being at the same position as any big watermelon at any time. To pick up a watermelon, she must be at the same position as that watermelon at some time step. Also, because Suika does not want to run around too much, at each time step she may either stay still or move to one of the four adjacent cells, as long as she does not leave the grid. If she moves to an adjacent cell, it counts as one move. At time , Suika has just taken her position and cannot move.
At each time step, if Suika chooses to move, you may assume that Suika and the watermelons move from their old positions to their new positions simultaneously, with no order.
Suika wants to know the minimum number of moves needed to avoid all big watermelons and collect all small watermelons.
Input Format
The first line contains five integers , as described above.
The second line contains two integers , as described above.
Then follow blocks. Each block describes a watermelon's appearance time, disappearance time, movement, and whether it can be picked up:
- First line: two integers , meaning the watermelon appears at time and disappears at time . If , the watermelon does not disappear even at the last time step. It is guaranteed that each watermelon exists for at least one time step.
- Next line: one integer , either or . means this watermelon must be avoided; means this watermelon must be picked up. It is guaranteed that exactly watermelons need to be picked up.
- Next lines: each line contains two integers , in order describing the coordinates of this watermelon from time to time . A watermelon’s movement may be non-continuous and happens instantaneously, so you do not need to consider whether Suika was on the movement path.
Output Format
If Suika cannot avoid being hit by any big watermelon during the time steps or cannot collect all small watermelons, output . Otherwise, output a single integer, the minimum number of moves Suika needs.
5 5 10 3 3
1 1
1 11
1
3 4
5 2
3 5
1 1
5 4
3 4
2 1
1 1
1 1
5 5
1
Hint
Sample Explanation
From times to , Suika stays still. At time , a watermelon appears next to her; Suika can move to to pick it up.
Constraints and Hint
This problem uses bundled testdata.
Subtask 1: has special properties A and B.
Subtasks 2–3: has only special property A.
Subtasks 4–5: has only special property B.
Subtasks 6–10: has neither special property.
Special property A: For all watermelons, . All watermelons stay still the whole time.
Special property B: .
For all subtasks, the following hold:
.
.
$1 \le h, w \le 5, 1 \le T \le 100, 1 \le t1 \le T, 2 \le t2 \le T + 1, t1 < t2$.
It is guaranteed that no position will contain two or more watermelons at the same time.
Translated by ChatGPT 5
京公网安备 11011102002149号