Soccer Stadium
문제
Nagyerdő is a square-shaped forest located in the city of Debrecen, which can be modeled as an grid of cells. The rows of the grid are numbered from to from north to south, and the columns are numbered from to from west to east. We refer to the cell located at row and column of the grid as cell .
In the forest, each cell is either empty or contains a tree. At least one cell in the forest is empty.
DVSC, the famous sports club of the city, is planning to build a new soccer stadium in the forest. A stadium of size (where ) is a set of distinct empty cells .
- for each from to , inclusive, cell is empty,
- for each such that , at least one of and holds.
Soccer is played using a ball that is moved around the cells of the stadium. A straight kick is defined to be either of the following two actions:
- Move the ball from cell to cell (), where the stadium contains all cells between cell and in row . Formally,
- if then the stadium should contain cell for each such that ,
- if then the stadium should contain cell for each such that .
- Move the ball from cell to cell (), where the stadium contains all cells between cell and in column . Formally,
- if then the stadium should contain cell for each such that ,
- if then the stadium should contain cell for each such that .
A stadium is regular if it is possible to move the ball from any cell contained by the stadium to any other cell contained by the stadium with at most straight kicks. Note that any stadium of size is regular.
For example, consider a forest of size , with cells and containing trees and every other cell being empty. The figure below shows three possible stadiums. Cells with trees are darkened, and cells contained by the stadium are striped.
The stadium on the left is regular. However, the stadium in the middle is not regular, because at least straight kicks are needed to move the ball from cell to . The stadium on the right is also not regular, because it is impossible to move the ball from cell to using straight kicks.
The sports club wants to build a regular stadium that is as big as possible. Your task is to find the maximum value of such that there exists a regular stadium of size in the forest.