#P10923. Happybob's Pencil Case (UBC001C)
Happybob's Pencil Case (UBC001C)
Background
Note: There are no typos in this problem.
Problem Description
Suppose the classroom is an 01 matrix, where 0 means empty and 1 means there is a desk (an obstacle).
Now Cuazyoxi is holding Happybob's Pencil Case at , and Happybob is at .
We define one move as moving from the current cell to one of the four adjacent cells (up, down, left, or right). Formally, suppose a person (Cuazyoxi or Happybob) is currently at . If one of , , , exists and is not an obstacle, then he may move to that cell.
Every second, Cuazyoxi moves once or stays still first, and then Happybob moves once, twice, or stays still. After each move, both of them know the other person's position.
Both sides are very smart. Cuazyoxi wants to delay being caught by Happybob for as long as possible, while Happybob wants to catch Cuazyoxi as early as possible.
Question: How many more seconds can Cuazyoxi evade Happybob (i.e., at least how many seconds does Happybob need before he can reach the same cell as Cuazyoxi)?
Input Format
The first line contains a positive integer , which is the size of the classroom.
The second line contains four positive integers , representing the starting positions of Cuazyoxi and Happybob.
The next lines each contain a string of length . These strings form a 01 matrix.
Output Format
If Cuazyoxi will eventually be caught, output the time when he is caught. Otherwise, output inf.
3
1 1 3 3
011
011
000
2
3
1 1 3 3
011
111
110
inf
Hint
Sample Explanation
For sample , Cuazyoxi's optimal strategy is clearly to stay in place. After seconds, Happybob can catch him.
For sample , no matter what happens, Happybob cannot catch Cuazyoxi.
Constraints
and . It is guaranteed that the numbers at and are 0, and either or . It is guaranteed that each of the input strings has length and contains only characters 0 and 1 (it may contain only 1 or only 0).
Translated by ChatGPT 5