#P1374. 进攻幽暗城
进攻幽暗城
Description
The map of the Undercity is an grid of . If , then position is an obstacle and cannot be traversed; if , then position is passable.
Xiao A and Thrall start at , and the Dreadlord starts at . Xiao A’s goal is to reach the Dreadlord’s position.
Thrall moves according to a specific route, which is a digit string composed of digits to .
At second :
- If the -th digit (thinking of the digit string repeated infinitely) is , Thrall stays still this second.
- If it is , Thrall moves up by one cell this second.
- If it is , Thrall moves down by one cell this second.
- If it is , Thrall moves left by one cell this second.
- If it is , Thrall moves right by one cell this second.
If Thrall’s next position would be a wall or outside the maze, Thrall stays in place. The Dreadlord follows the same rule. (In other words, you can think of the digit string as repeating infinitely; at second , take the -th character of this infinite string.)
Each second, Xiao A may choose one of the four directions (up, down, left, right) and move one cell in that direction, provided the destination is not a wall and not out of bounds; or Xiao A may stay in place. However, due to the strange environment in the Undercity, Xiao A can remain outside Thrall’s “aura” for at most consecutive seconds; if this limit is exceeded, Xiao A dies. The aura has effective radius , meaning Xiao A receives Thrall’s aura effect only when the distance between Xiao A and Thrall is less than or equal to . If Xiao A leaves Thrall’s aura and then re-enters the effective area of the aura, the counter resets to zero the next time Xiao A leaves the aura.
Xiao A wants to know the minimum number of seconds needed to reach the Dreadlord’s position.
Input Format
The first line contains four integers .
The next lines each contain digits ( or ) without spaces, representing the map of the Undercity.
The next line contains four integers (, ).
The next line is a digit string describing Thrall’s movement.
The next line is a digit string describing the Dreadlord’s movement.
Output Format
Output a single integer on one line, the minimum time required.
3 4 7 3
1010
0000
0101
1 2 3 3
0132401
12131
3
Hint
Source: kiro, original.
Constraints: For of the testdata, , , , length of the digit string , answer .
Translated by ChatGPT 5
京公网安备 11011102002149号