問題一覧 > 通常問題

No.1130 Grid Numbers

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 250
作問者 : leafirby / テスター : null
お気に入りにしたユーザー ProblemId : 4560 / 自分の提出
問題文最終更新日: 2020-07-20 21:54:28
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original

Problem Statement

Iot-kun decided to write one of the digits from $0$ to $9$ in each cell of an $H\times W$ grid.
After writing digits in all the cells, Iot-kun became curious about how many of each digit there are, so in order to count them easily, he decided to rearrange them in ascending order starting from $0$.
Specifically, letting $A_{i,j}$ be the digit written in row $i$, column $j$ of the grid, he arranges them so that $\begin{cases} A_{i,j}\le A_{i,j+1} & (j < W) \\ A_{i,j}\le A_{i+1,1} & (j = W) \\ \end{cases}$ holds.
For example, if the grid is in the following state

9 0 2 3 8  
1 1 4 5 1  
9 8 6 4 0  
1 9 7 0 9
then he rearranges it as follows:
0 0 0 1 1  
1 1 2 3 4  
4 5 6 7 8  
8 9 9 9 9
Find the grid after this rearrangement.

Input

$H\ W$  
$A_{1,1}\ A_{1,2}\ ....A_{1,W}$  
$A_{2,1}\ A_{2,2}\ ....A_{2,W}$  
$\ \ :\ \ \ \ :\ \ \ \ \ \ \ \ \ \ \ :$  
$\ \ :\ \ \ \ :\ \ \ \ \ \ \ \ \ \ \ :$  
$A_{H,1}\ A_{H,2}\ ....A_{H,W}$

$0 < H,W\le 100$
$0\le A_{i,j}\le 9$
All inputs are integers.

Output

Output the grid after the rearrangement in the following format, followed by a newline at the end.

$A'_{1,1}\ A'_{1,2}\ ....A'_{1,W}$  
$A'_{2,1}\ A'_{2,2}\ ....A'_{2,W}$  
$\ \ :\ \ \ \ :\ \ \ \ \ \ \ \ \ \ \ :$  
$\ \ :\ \ \ \ :\ \ \ \ \ \ \ \ \ \ \ :$  
$A'_{H,1}\ A'_{H,2}\ ....A'_{H,W}$

Sample

Sample 1
Input
4 5
9 0 2 3 8
1 1 4 5 1
9 8 6 4 0
1 9 7 0 9
Output
0 0 0 1 1
1 1 2 3 4
4 5 6 7 8
8 9 9 9 9

Sample 2
Input
5 3
1 1 1
1 1 2
2 2 2
2 3 3
3 3 3 
Output
1 1 1
1 1 2
2 2 2
2 3 3
3 3 3

Source (the problem statement has been partially modified.)

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。