It is often heard that the apple doesn't fall far from the tree. But is that really so?
The National Statistics Department has tracked the falling of apples in a fruit garden for
Interestingly enough, each year there was exactly one apple fall, so the Department decided to write down
Your task is to determine the squared distance between the nearest tree and the apple that fell, measured in unit fields of the matrix (we assume it is that tree from which the apple fell).
The distance between fields
Input
The first line of input contains two integers,
Each of the following x
or .
. The character .
denotes an empty field, and the character x
denotes a field with at least one tree.
The fruit garden will initially contain at least one tree.
After that, an integer
Each of the following
Output
Output
Scoring
In test cases worth 30% of total points, it will hold
Sample Input 1
3 3
x..
...
...
3
1 3
1 1
3 2
Sample Output 1
4
0
5
Explanation for Sample Output 1
The closest apple to the one that fell in the first year is the apple in the field
Sample Input 2
5 5
..x..
....x
.....
.....
.....
4
3 1
5 3
4 5
3 5
Sample Output 2
8
8
4
1
Comments
I think there's a little typo on the definition of the distance:
It should be without square root according to the problem statement.
The formula given is for distance, you're to output the square of that, similar to this problem.