#P13563. 「WWOI R1」WSM 游戏
「WWOI R1」WSM 游戏
Background
is an adventure game, and WSM is the main character of this game.
Problem Description
There is a map made of a grid with rows and columns. WSM starts from the top-left cell with coordinates and needs to reach the cell with coordinates .
There are password locks and password keys on the map.
When WSM arrives at the cell containing a key with password , the lock with password disappears immediately.
At any moment, WSM must stay within the map, and the cell WSM is in must not have a lock.
If a cell contains both a lock with password and a key with password , then WSM can enter that cell.
There are also normal items and magic items on the map. WSM can spend steps to use normal items and magic items on the map. All items and magic items can be reused.
Normal items are very primitive: WSM can only use an item that is in the same cell as WSM.
Suppose WSM is currently at . After using an item, WSM moves to .
| Item ID | Position after moving |
|---|---|
| WSM moves up by one cell, i.e. | |
| WSM moves down by one cell, i.e. | |
| WSM moves left by one cell, i.e. | |
| WSM moves right by one cell, i.e. |
Magic items are fragile: when WSM is in the same cell as some magic item, that magic item will disappear permanently.
Magic items are powerful: WSM can use any magic item on the map.
Suppose WSM is currently at , and the magic item is at . After using the magic item, WSM moves to .
| Magic item ID | Position after moving |
|---|---|
| , | |
| , | |
| , |
In each step, WSM can use one normal item or one magic item. What is the minimum number of steps needed to move from the cell to the cell ?
Input Format
The first line contains four integers .
The second line contains four integers .
The next lines each contain three integers , meaning there is a lock with password at cell .
The next lines each contain three integers , meaning there is a key with password at cell .
The next lines each contain three integers , meaning there is a normal item with ID at cell .
The next lines each contain three integers , meaning there is a magic item with ID at cell .
Output Format
Output one integer, the minimum number of steps WSM needs. If it is impossible to reach, output -1.
2 2 2 2
0 0 8 0
1 2 4
1 1 2
2 2 1
1 1 4
2 2 4
2 1 4
1 2 3
2 1 1
2
Hint
Sample Explanation
The route with the minimum number of steps is:
$\def\f#1{\xrightarrow{\bf 道具#1}} (1,1) \f{2} (2,1) \f{4} (2,2)$。
Constraints
This problem uses bundled testdata.
Note: In any cell, there may simultaneously exist multiple locks, keys, items, and magic items.
For all testdata, it is guaranteed that:
- ,,。
- ,,,。
- For all locks, keys, items, and magic items, ,。
- For all locks, 。
- For all keys, 。
- For all normal items, 。
- For all magic items, 。
| Subtask ID | Score | |||||
|---|---|---|---|---|---|---|
| ^ | ||||||
| ^ | ^ | |||||
| ^ | ^ | |||||
| ^ | ^ | |||||
Translated by ChatGPT 5