Soccer Stadium

시간 제한3.5초메모리 제한1024 MB

요약
나무가 있는 칸이 섞인 N×N 격자에서, 경기장에 속한 임의의 두 칸을 가로 또는 세로 직선 킥 두 번 이내로 오갈 수 있게 하는 빈 칸 집합의 최대 크기를 구한다.
난이도

어려움10점 중 8점

유형
행렬, 누적 합, 구현, 완전 탐색
정답자
아직 제출이 없습니다

문제

Nagyerdő is a square-shaped forest located in the city of Debrecen, which can be modeled as an N×NN \times N grid of cells. The rows of the grid are numbered from 00 to N−1N - 1 from north to south, and the columns are numbered from 00 to N−1N - 1 from west to east. We refer to the cell located at row rr and column cc of the grid as cell (r,c)(r, c).

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 ss (where s≥1s \ge 1) is a set of ss distinct empty cells (r_0,c_0),…,(r_s−1,c_s−1)(r\_0, c\_0), \ldots, (r\_{s - 1}, c\_{s - 1}).

  • for each ii from 00 to s−1s - 1, inclusive, cell (r_i,c_i)(r\_i, c\_i) is empty,
  • for each i,ji, j such that 0≤i<j<s0 \le i \lt j \lt s, at least one of r_i≠r_jr\_i \neq r\_j and c_i≠c_jc\_i \neq c\_j 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 (r,a)(r,a) to cell (r,b)(r,b) (0≤r,a,b<N,a≠b0 \le r,a,b \lt N, a \ne b), where the stadium contains all cells between cell (r,a)(r,a) and (r,b)(r,b) in row rr. Formally,

    • if a<ba \lt b then the stadium should contain cell (r,k)(r,k) for each kk such that a≤k≤ba \le k \le b,
    • if a>ba \gt b then the stadium should contain cell (r,k)(r,k) for each kk such that b≤k≤ab \le k \le a.
  • Move the ball from cell (a,c)(a,c) to cell (b,c)(b,c) (0≤c,a,b<N,a≠b0 \le c,a,b \lt N, a \ne b), where the stadium contains all cells between cell (a,c)(a,c) and (b,c)(b,c) in column cc. Formally,

    • if a<ba \lt b then the stadium should contain cell (k,c)(k,c) for each kk such that a≤k≤ba \le k \le b,
    • if a>ba \gt b then the stadium should contain cell (k,c)(k,c) for each kk such that b≤k≤ab \le k \le a.

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 22 straight kicks. Note that any stadium of size 11 is regular.

For example, consider a forest of size N=5N = 5, with cells (1,0)(1,0) and (4,2)(4,2) 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 33 straight kicks are needed to move the ball from cell (4,1)(4,1) to (4,3)(4,3). The stadium on the right is also not regular, because it is impossible to move the ball from cell (3,0)(3,0) to (1,3)(1,3) 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 ss such that there exists a regular stadium of size ss in the forest.

제한

  • 1≤N≤2,0001 \le N \le 2\\,000
  • 0≤F\[i]\[j]≤10 \le F\[i]\[j] \le 1 (for each ii and jj such that 0≤i<N0 \le i \lt N and 0≤j<N0 \le j \lt N)
  • There is at least one empty cell in the forest. In other words, F\[i]\[j]=0F\[i]\[j] = 0 for some 0≤i<N0 \le i \lt N and 0≤j<N0 \le j \lt N.

예제

이 문제는 공개된 예제가 없습니다.