#P1332. Plague Spread in the Legion
Plague Spread in the Legion
Plague Spread in the Legion
A legion is represented as an \(n\) by \(m\) matrix, where each cell is occupied by a member of the Crimson Vanguard. A deadly plague starts from a known infection source and spreads to the four adjacent cells (up, down, left, right) every hour. The plague continues to spread until every member of the legion is infected. Your task is to compute the time required for the farthest member (symbolizing the leaders of the Crimson Vanguard) to be infected.
The time required is effectively the maximum Manhattan distance from the infection source to any cell in the matrix, which can be mathematically expressed as:
[ T = \max(r, n-1-r) + \max(c, m-1-c), ]
where \(r\) and \(c\) denote the row and column of the infection source (0-indexed), and \(n\) and \(m\) are the total number of rows and columns, respectively.
inputFormat
The input consists of two lines:
- The first line contains two integers \(n\) and \(m\) representing the number of rows and columns of the legion matrix respectively.
- The second line contains two integers \(r\) and \(c\) representing the 0-indexed row and column of the infection source. It is guaranteed that \(0 \le r < n\) and \(0 \le c < m\).
outputFormat
Output a single integer representing the time (in hours) it takes for the plague to reach the farthest cell (i.e. the time when the Crimson Vanguard leaders get infected).
sample
3 3
1 1
2