欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1986B.Matrix Stabilization
Matrix Stabilization
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.
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.
Note
In the first set of input data, the algorithm will select the cell twice in a row and then terminate.

In the second set of input data, there is no cell whose value is strictly greater than the values of all neighboring cells.
In the third set of input data, the algorithm will select the cell and then terminate.

In the fourth set of input data, the algorithm will select the cell three times and then the cell twice.

Samples
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
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |