410493: GYM104027 F 落石

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

F. 落石time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

$$$n*m$$$的网格空间中有许多矩形的落石,这些石头只会向下落,并且在遇到其它石头后就会停止(不考虑平衡问题)。请你计算一下石头最终的状态。

Input

第一行输入两个数$$$n,m(1\le n,m\le 1000)$$$代表网格空间的长宽。 接下里$$$n$$$行,每行$$$m$$$个整数,代表空间状况。数字为0代表该位置为空,若为其它数字则代表石头。同一块石头的数字相同。

Output

输出$$$n$$$行每行$$$m$$$个数,代表最终状态。

ExampleInput
6 5
4 4 0 1 1
0 0 0 0 0
0 2 2 5 0
0 2 2 0 0
0 0 0 0 0
0 0 3 3 0
Output
0 0 0 0 0 
0 0 0 0 0 
4 4 0 0 0 
0 2 2 1 1 
0 2 2 5 0 
0 0 3 3 0 

加入题单

算法标签: