거대한 R행 C열 격자에서 N개의 시작 잔디 세포가 주어질 때, 매년 바람 방향을 정해 잔디를 한 칸씩 퍼뜨리며 모든 칸을 덮는 최소 연수를 구한다.
어려움8이분 탐색그리디수학구현아직 제출이 없습니다시간 제한2초메모리 제한512 MBIn 21XX, the residents of the IOI planet plan to immigrate to a recently discovered planet.
The new planet has a field, which is a rectangular grid with R rows and C columns. The columns are parallel to the south-north direction, and the rows are parallel to the east-west direction. The cell in the i-th row from north and the j-th column from west is called the cell (i, j). The north-west corner of the field is the cell (1, 1), and the south-east corner is the cell (R,C). In each year, the residents of the IOI planet choose the direction of the wind blowing on the field. The direction is one of east, west, south, or north.
To engage in agriculture in the new planet, they will plant “JOI grasses” in all over the field in the new planet. In the spring of the first year of immigration, N cells in the field have JOI grasses.
The range of JOI grasses are expanded by the wind. Each summer, the seeds of JOI grasses are blown by the wind to the direction chosen by the residents of the IOI planet. The seeds move one cell to the direction of the wind, and they land on. If the seeds land on a cell of the field without JOI grasses, it will have JOI grasses in the spring of the next year. Once a cell has JOI grasses, it will keep JOI grasses in the future.
We want to calculate the minimum number of years until all the cells in the field have JOI grasses if we adjust the direction of the wind appropriately.
Write a program which calculates the minimum number of years until all the cells in the field have JOI grasses if we adjust the direction of the wind appropriately.
Read the following data from the standard input.
Write one line to the standard output. The output contains the minimum number of years until all the cells in the field have JOI grasses if we adjust the direction of the wind appropriately.