#O. JIXMPII5JUhKW00#%[+
JIXMPII5JUhKW00#%[+
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
Statement
You are given a matrix of size , where the rows are numbered from to from top to bottom, and the columns are numbered from to from left to right. The element at the intersection of the -th row and the -th column is denoted by .
Consider the algorithm for stabilizing matrix :
- Find the cell such that its value is strictly greater than the values of all its neighboring cells. If there is no such cell, terminate the algorithm. If there are multiple such cells, choose the cell with the smallest value of , and if there are still multiple cells, choose the one with the smallest value of .
- Set .
- Go to step .
In this problem, cells and are considered neighbors if they share a common side, i.e., .
Your task is to output the matrix after the stabilization algorithm has been executed. It can be shown that this algorithm cannot run for an infinite number of iterations.
Format
Input
Each test consists of multiple sets of input data. The first line contains a single integer ( ) — the number of sets of input data. This is followed by their description.
The first line of each set of input data contains two integers and ( ) — the number of rows and columns of matrix .
The next lines describe the corresponding rows of the matrix. The -th line contains integers ( ).
It is guaranteed that the sum of over all sets of input data does not exceed .
Output
For each set of input data, output lines with numbers in each line — the values of the cells of matrix after the stabilization algorithm.
Sample
6
1 2
3 1
2 1
1
1
2 2
1 2
3 4
2 3
7 4 5
1 8 10
5 4
92 74 31 74
74 92 17 7
31 17 92 3
74 7 3 92
7 31 1 1
3 3
1000000000 1 1000000000
1 1000000000 1
1000000000 1 1000000000
1 1
1
1
1 2
3 3
4 4 5
1 8 8
74 74 31 31
74 74 17 7
31 17 17 3
31 7 3 3
7 7 1 1
1 1 1
1 1 1
1 1 1
ShanghaiTech ACM 炸鱼杯
- 状态
- 已结束
- 规则
- OI
- 题目
- 46
- 开始于
- 2024-12-10 23:00
- 结束于
- 2024-12-15 13:00
- 持续时间
- 110 小时
- 主持人
- 参赛人数
- 112