#abc363e. E - Sinking Land
E - Sinking Land
Score : points
问题陈述
有一个大小为 的岛屿,被海包围。 岛屿被划分为 行和 列的 区域,第 行从顶部和第 列从左侧(相对于当前海平面)的区域的海拔高度是 。
从现在开始,海平面每年上升 。 在这里,与海相邻的区域或海拔高度不大于海平面的沉入海中的区域将会沉入海中。 在这里,当一个区域新沉入海中时,任何与它垂直或水平相邻且海拔高度不大于海平面的区域也会同时沉入海中,并且这个过程会重复进行。
对于每个 ,找出 年后仍然高于海平面的岛屿面积。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
There is an island of size , surrounded by the sea.
The island is divided into rows and columns of sections, and the elevation of the section at the -th row from the top and the -th column from the left (relative to the current sea level) is .
Starting from now, the sea level rises by each year.
Here, a section that is vertically or horizontally adjacent to the sea or a section sunk into the sea and has an elevation not greater than the sea level will sink into the sea.
Here, when a section newly sinks into the sea, any vertically or horizontally adjacent section with an elevation not greater than the sea level will also sink into the sea simultaneously, and this process repeats for the newly sunk sections.
For each , find the area of the island that remains above sea level years from now.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print lines. The -th line should contain the area of the island that remains above sea level years from now.
Sample Input 1
3 3 5
10 2 10
3 1 4
10 5 10
Sample Output 1
9
7
6
5
4
Let denote the section at the -th row from the top and the -th column from the left. Then, the following happens:
- After year, the sea level is higher than now by , but there are no sections with an elevation of that are adjacent to the sea, so no sections sink. Thus, the first line should contain .
- After years, the sea level is higher than now by , and sinks into the sea. This makes adjacent to a sunken section, and its elevation is not greater than , so it also sinks. No other sections sink at this point. Thus, two sections sink, and the second line should contain .
- After years, the sea level is higher than now by , and sinks into the sea. No other sections sink. Thus, the third line should contain .
- After years, the sea level is higher than now by , and sinks into the sea. No other sections sink. Thus, the fourth line should contain .
- After years, the sea level is higher than now by , and sinks into the sea. No other sections sink. Thus, the fifth line should contain .
Therefore, print , , , , in this order, each on a new line.
Sample Input 2
3 5 3
2 2 3 3 3
2 1 2 1 3
2 2 3 3 3
Sample Output 2
15
7
0