#P9602. [IOI 2023] 足球场

[IOI 2023] 足球场

Background

This is an interactive problem. You only need to implement the function required in the code.

Your code does not need to include any additional header files, and you do not need to implement the main function.

This problem only supports C++ submissions.

Problem Description

In the city of Debrecen, there is a square forest called Nagyerdő, which can be viewed as an N×NN \times N grid. The rows of the grid are numbered from 00 to N1N - 1 from north to south, and the columns are numbered from 00 to N1N - 1 from west to east. The cell in row rr and column cc is called cell (r,c)(r, c).

Each cell in the forest is either empty or has a tree. There is at least one empty cell in the forest.

DVSC is the most famous sports club in the city and is currently planning to build a new football stadium in the forest. A stadium of size ss (where s1s \ge 1) is a set of ss distinct empty cells (r0,c0),,(rs1,cs1)(r_0, c_0), \ldots, (r_{s - 1}, c_{s - 1}). Formally, this means:

  • For each ii from 00 to s1s - 1 (inclusive), the cell (ri,ci)(r_i, c_i) is empty;
  • For each pair ii and jj such that 0i<j<s0 \le i \lt j \lt s, at least one of rirjr_i \neq r_j and cicjc_i \neq c_j holds.

When playing, the ball is passed between the cells of the stadium. A direct pass is one of the following two actions:

  • The stadium contains all cells between (r,a)(r,a) and (r,b)(r,b) in row rr, and the ball is passed from cell (r,a)(r,a) to cell (r,b)(r,b) (0r,a,b<N,ab0 \le r,a,b \lt N, a \ne b). The containment is defined formally as:
    • If a<ba \lt b, then the stadium should contain every cell (r,k)(r,k) such that akba \le k \le b;
    • If a>ba \gt b, then the stadium should contain every cell (r,k)(r,k) such that bkab \le k \le a.
  • The stadium contains all cells between (a,c)(a,c) and (b,c)(b,c) in column cc, and the ball is passed from cell (a,c)(a,c) to cell (b,c)(b,c) (0c,a,b<N,ab0 \le c,a,b \lt N, a \ne b). The containment is defined formally as:
    • If a<ba \lt b, then the stadium should contain every cell (k,c)(k, c) such that akba \le k \le b;
    • If a>ba \gt b, then the stadium should contain every cell (k,c)(k, c) such that bkab \le k \le a.

A stadium is called regular if it is possible to pass the ball from any cell of the stadium to any other cell of the stadium using at most 22 direct passes. Note that any stadium of size 11 is regular.

For example, consider a forest of size N=5N = 5 in which cells (1,0)(1,0) and (4,2)(4,2) have trees and all other cells are empty. The figure below shows three possible stadiums. Cells with trees are shown in dark color, and cells belonging to the stadium are hatched.

The stadium on the left is regular. However, the stadium in the middle is not regular, because passing the ball from cell (4,1)(4,1) to cell (4,3)(4,3) requires at least 33 direct passes. The stadium on the right is also not regular, because it is impossible to pass the ball from cell (3,0)(3,0) to cell (1,3)(1,3) using direct passes.

The club wants to build the largest possible regular stadium. Your task is to find the maximum value of ss such that a regular stadium of size ss can be built in the forest.

Input Format

You need to implement the following function:

int biggest_stadium(int N, int[][] F)
  • NN: the size of the forest.
  • FF: an array of length NN, where each element is an array of length NN, describing the cells of the forest. For each rr and cc such that 0r<N0 \le r \lt N and 0c<N0 \le c \lt N, F[r][c]=0F[r][c] = 0 means cell (r,c)(r, c) is empty, and F[r][c]=1F[r][c] = 1 means the cell has a tree.
  • The function should return the maximum size of a regular stadium that can be built in the forest.
  • For each test case, this function is called exactly once.

Output Format

Consider the following call:

biggest_stadium(5, [[0, 0, 0, 0, 0],  
                    [1, 0, 0, 0, 0], 
                    [0, 0, 0, 0, 0], 
                    [0, 0, 0, 0, 0], 
                    [0, 0, 1, 0, 0]])

The forest described by this example is shown on the left of the figure below, and a regular stadium of size 2020 is shown on the right:

Since there is no regular stadium of size 2121 or larger, the function should return 2020.

Hint

Constraints

  • 1N20001 \le N \le 2\,000
  • 0F[i][j]10 \le F[i][j] \le 1 (for all ii and jj such that 0i<N0 \le i \lt N and 0j<N0 \le j \lt N)
  • There is at least one empty cell in the forest. That is, there exist ii and jj such that 0i<N0 \le i \lt N and 0j<N0 \le j \lt N and F[i][j]=0F[i][j] = 0.

Subtasks

  1. (6 points) At most one cell has a tree.
  2. (8 points) N3N \le 3.
  3. (22 points) N7N \le 7.
  4. (18 points) N30N \le 30.
  5. (16 points) N500N \le 500.
  6. (30 points) No additional constraints.

In each subtask, if your program can correctly determine whether the set of all empty cells can form a regular stadium, then you will receive 25% of the partial score for that subtask.

More precisely, for test cases where the set of all empty cells is a regular stadium, your solution is scored as follows:

  • If you return the correct answer (that is, the number of all empty cells), you get full score;
  • Otherwise, you get 0 points.

For test cases where the set of all empty cells is not a regular stadium, your solution is scored as follows:

  • If you return the correct answer, you get full score;
  • If you return the number of all empty cells, you get 0 points;
  • If you return any other value, you get 25% of the score.

The score for each subtask is the minimum score among all test cases in that subtask.

Sample grader

The sample grader reads the input in the following format:

  • Line 11: NN.
  • Line 2+i2 + i (0i<N0 \le i \lt N): F[i][0]  F[i][1]    F[i][N1]F[i][0] \; F[i][1] \; \ldots \; F[i][N - 1].

The sample grader prints your answer in the following format:

  • Line 11: the return value of the function biggest_stadium.

Translated by ChatGPT 5