#P2427. Wave
Wave
Description
The propagation speed of waves differs across media. In vacuum, all wave speeds are m/s, while in liquid media the wave speed is lower than in vacuum and also varies between different liquid media. We divide a liquid surface into an grid of equal-sized square cells, each cell containing exactly one liquid medium. We want to know, for a wave emitted from some source, how large an axis-aligned square centered at the source the wave can extend to while maintaining an unchanged wave speed. Assume all such squares are axis-aligned with the coordinate axes.
Input Format
The first line contains three integers , denoting the number of rows and columns of the grid and the number of queries, respectively. Then follows an matrix in which each element is a lowercase letter representing the medium in the corresponding cell; different letters denote different media. Then follow lines, each with two integers and describing a query: the side length of the largest axis-aligned square centered at row , column within which the wave can extend while maintaining an unchanged wave speed is requested. Rows are numbered from to , and columns from to .
Output Format
Output lines, each containing one integer, the answer to the corresponding query.
5 5 3
abbaa
abbaa
aaaaa
aaaaa
aaaaa
1 2
1 4
3 2
1
1
3
Hint
For of the testdata, , .
For of the testdata, , .
Translated by ChatGPT 5
京公网安备 11011102002149号