#K84992. Maximum Diversity Score
Maximum Diversity Score
Maximum Diversity Score
You are given an \(n \times n\) grid, where each cell contains an integer representing a flower species. A sub-grid is defined as any contiguous rectangular block within the grid. The diversity score of a sub-grid is the number of distinct species present in that sub-grid.
Your task is to find the maximum diversity score among all possible sub-grids of the given grid. Formally, for a sub-grid defined by its top-left corner \((i,j)\) and bottom-right corner \((x,y)\), the diversity score is given by:
[ \text{score} = \text{number of distinct elements in } { grid[k][l] \mid i \leq k \leq x,\ j \leq l \leq y } ]
Compute and output the maximum diversity score over all such sub-grids.
inputFormat
The first line contains a single integer \(n\), which is the size of the grid. Each of the next \(n\) lines contains \(n\) space-separated integers, representing the grid rows.
For example, a sample input might look like:
3 1 2 3 4 5 6 7 8 9
outputFormat
Output a single integer, which is the maximum diversity score among all possible sub-grids.
For the sample input above, the correct output is:
9## sample
3
1 2 3
4 5 6
7 8 9
9
</p>