#P6474. [NOI Online #2 入门组] 荆轲刺秦王
[NOI Online #2 入门组] 荆轲刺秦王
Background
This testdata is handmade. Hacks are welcome.
The 18th group of testdata trapped many people, and it is provided in the attachment for checking.
Problem Description
After several years, the assassin Jing Ke comes to the Xianyang Palace again, trying to assassinate Ying Zheng.
The map of the Xianyang Palace can be described as a rectangle with rows and columns. Here, we define that in each row, from left to right is the positive direction of the axis, and in each column, from bottom to top is the positive direction of the axis. The coordinate of the bottom-left corner is . Points in the rectangle can be divided into types:
- The start point, where Jing Ke is located, represented by the character
Son the map. - The end point, where Ying Zheng is located, represented by the character
Ton the map. - Guards, represented by a positive integer . A guard at can observe points whose Manhattan distance to him is less than . That is, the guard at can observe all points satisfying .
- Empty ground, represented by the character
.on the map.
Jing Ke’s normal movement is to move one grid per second to any of the eight 8-connected directions. As shown in the figure below, the middle point is Jing Ke’s current position, and every second, he can move to any of the other eight points.

Note that during normal movement, Jing Ke cannot step into any cell that has a guard or is observable by any guard. Of course, he also cannot leave the Xianyang Palace, meaning that at any time, Jing Ke’s coordinates must satisfy and .
Jing Ke also has two skills: Invisibility and Teleportation.
- Invisibility: In the next second, Jing Ke enters an invisible state. Guards cannot observe Jing Ke, and Jing Ke may enter cells within guards’ observable ranges, but he still cannot enter the cell where a guard stands. Note that this state lasts for only one second.
- Teleportation: In the next second, Jing Ke’s moving distance becomes , but he can only move in the four directions up, down, left, and right. That is, he can move to
, , , .
In this problem, the two skills can be used at the same time, and there is no cooldown. That is, after using a skill once, you may use it again immediately. Both skills have usage limits, and you do not have to use all of them.
Now, given the map of Xianyang, compute the minimum time needed for Jing Ke to reach the King of Qin’s position. In addition, among solutions with the same time, Jing Ke wants the total number of times the two skills are used to be as small as possible. If both the time and the total skill usage are the same, Jing Ke wants the number of invisibility uses to be as small as possible.
Input Format
The first line contains five integers , , , , , meaning the map size is , the usage limit of invisibility is , the usage limit of teleportation is , and the teleport distance is .
Then follow lines, each with elements. Each element is the character S, T, ., or a positive integer , representing a grid point. See the problem description for details.
Output Format
If Jing Ke cannot reach the King of Qin’s position, output one line with .
Otherwise, output one line with three integers , , , representing the minimum required time, the number of invisibility uses, and the number of teleportation uses, in this order.
5 4 0 0 5
. 1 T 1
. . . 2
. 1 . .
S . . .
1 . . .
3 0 0
8 6 2 3 3
. S . . . .
. . . . . .
. . . . . .
. . . . . .
. . . . . .
2 . 2 . 2 .
. . 1 . T .
3 . 1 . . 3
3 1 3
8 6 5 5 2
. S . . . .
. . . . . .
. . . . . .
1 1 3 2 . 1
2 3 2 2 1 3
3 2 4 1 4 3
2 6 1 5 T 2
8 1 6 3 2 10
-1
Hint
Sample 1 Explanation
The start point is . Jing Ke can move to , , in order to reach the end point.
Sample 2 Explanation
The start point is . Jing Ke can move to , , in order. Note that even though the last step reaches the end point, since the end point is within a guard’s observable range, Jing Ke still needs invisibility to enter.
Constraints and Hints
For test points : , , . It is guaranteed that the minimum required time does not exceed , or there is no solution.
For test points : , , . It is guaranteed that the position of T is not within any guard’s observable range.
For test points : , , .
For test points : , , , .
For test points : the number of guards does not exceed .
For all test points: , , , , , .
It is guaranteed that the position of S is not within any guard’s observable range.
Translated by ChatGPT 5