#P7663. [COCI 2014/2015 #5] JABUKE
[COCI 2014/2015 #5] JABUKE
Description
You are given an matrix, where apple trees are represented by x, and empty cells are represented by ..
There are years. Each year, an apple falls from the sky onto the coordinate . You need to output the square of the distance from this apple to the nearest apple tree. Of course, after one year, this apple will grow into a new apple tree, and it will be included in the computation for the apple that falls in the next year.
Input Format
The first line contains two positive integers , representing the matrix's height and width.
The next lines each contain characters, consisting only of x and ., describing the matrix.
Then a positive integer is given, representing the number of years.
The next lines each contain two positive integers , representing the position where the apple falls each year.
Output Format
Output lines in total. Each line contains one integer, representing the square of the distance from the falling apple to the nearest apple tree at that time.
3 3
x..
...
...
3
1 3
1 1
3 2
4
0
5
5 5
..x..
....x
.....
.....
.....
4
3 1
5 3
4 5
3 5
8
8
4
1
Hint
For of the testdata, .
For of the testdata, , . It is guaranteed that the initial matrix contains at least one apple tree.
Distance formula: $d((x_1,y_1),(x_2,y_2))=\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$.
Translated from COCI 2014/2015 CONTEST #5。
Translated by ChatGPT 5
京公网安备 11011102002149号