#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 grid. The rows of the grid are numbered from to from north to south, and the columns are numbered from to from west to east. The cell in row and column is called cell .
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 (where ) is a set of distinct empty cells . Formally, this means:
- For each from to (inclusive), the cell is empty;
- For each pair and such that , at least one of and 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 and in row , and the ball is passed from cell to cell (). The containment is defined formally as:
- If , then the stadium should contain every cell such that ;
- If , then the stadium should contain every cell such that .
- The stadium contains all cells between and in column , and the ball is passed from cell to cell (). The containment is defined formally as:
- If , then the stadium should contain every cell such that ;
- If , then the stadium should contain every cell such that .
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 direct passes. Note that any stadium of size is regular.
For example, consider a forest of size in which cells and 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 to cell requires at least direct passes. The stadium on the right is also not regular, because it is impossible to pass the ball from cell to cell using direct passes.
The club wants to build the largest possible regular stadium. Your task is to find the maximum value of such that a regular stadium of size can be built in the forest.
Input Format
You need to implement the following function:
int biggest_stadium(int N, int[][] F)
- : the size of the forest.
- : an array of length , where each element is an array of length , describing the cells of the forest. For each and such that and , means cell is empty, and 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 is shown on the right:

Since there is no regular stadium of size or larger, the function should return .
Hint
Constraints
- (for all and such that and )
- There is at least one empty cell in the forest. That is, there exist and such that and and .
Subtasks
- (6 points) At most one cell has a tree.
- (8 points) .
- (22 points) .
- (18 points) .
- (16 points) .
- (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 : .
- Line (): .
The sample grader prints your answer in the following format:
- Line : the return value of the function
biggest_stadium.
Translated by ChatGPT 5