#P1141. 01迷宫
01迷宫
Description
There is an grid maze consisting only of digits and . If you are on a cell with , you may move to one of the 4 adjacent cells with . Similarly, if you are on a cell with , you may move to one of the 4 adjacent cells with .
Your task is: for the given maze, for each specified starting cell, determine how many cells are reachable (including the starting cell).
Input Format
The first line contains two positive integers .
The next lines each contain characters, each of which is either or , with no spaces between characters.
Then follow lines. Each line contains two positive integers , referring to the cell at row , column of the maze, asking how many cells are reachable starting from this cell.
Output Format
Output lines. For each query, print the corresponding answer.
2 2
01
10
1 1
2 2
4
4
Hint
For the sample, all cells are mutually reachable.
- For of the testdata, .
- For of the testdata, .
- For of the testdata, .
- For of the testdata, .
- For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号