#P2427. Propagation in Liquid Medium Grid
Propagation in Liquid Medium Grid
Propagation in Liquid Medium Grid
The speed of a wave varies among different media. In vacuum, the speed is always \(3\times10^8\) m/s. In liquid media, however, the wave speed is lower and may vary with the type of liquid. Consider a liquid surface that is divided into an \(N \times M\) grid of identical square cells. Each cell contains a single type of liquid with an associated wave propagation speed.
Given the grid and a wave source located at a specified cell, determine the maximum size of a centered square (with sides parallel to the coordinate axes) such that the wave can propagate with a uniform speed throughout the square. In other words, find the largest odd positive integer \(L = 2d+1\) (where \(d \geq 0\)) such that every cell in the square centered at the wave source and extending \(d\) cells in all four directions has the same propagation speed as that at the source cell.
Note: The grid indices are 1-indexed. The answer is the side length of the maximal square.
inputFormat
The first line of input contains two integers \(N\) and \(M\) (the number of rows and columns of the grid).
The second line contains two integers \(r\) and \(c\), the 1-indexed coordinates of the wave source in the grid.
The next \(N\) lines each contain \(M\) integers. The \(j\)th integer in the \(i\)th line represents the wave propagation speed in the cell located at row \(i\) and column \(j\). All speeds are positive integers.
outputFormat
Output a single integer, representing the side length of the largest square (centered at the wave source) in which all cells have the same wave propagation speed as the wave source cell.
sample
3 3
2 2
1 1 1
1 1 1
1 1 1
3