No.1130 Grid Numbers
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 9then he rearranges it as follows:
0 0 0 1 1 1 1 2 3 4 4 5 6 7 8 8 9 9 9 9Find 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
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
leafirby
null