No.3657 Gathering Stones
問題文最終更新日: 2026-08-30 01:57:02
English (AI translation)
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.
Back to the original
MMA Contest 022
(順位表)
の他の問題:
Problem Statement
sepa has an $N \times M$ board. Stones are placed on the board.
The state of the board is represented by $N$ strings $S_1, S_2, \ldots, S_N$, each of length $M$. For $S_{i,j}$:
- If $S_{i,j}$ is
#, a stone is placed on the cell in the $i$-th row from the top and the $j$-th column from the left. - If $S_{i,j}$ is
., no stone is placed on the cell in the $i$-th row from the top and the $j$-th column from the left.
sepa will now perform the following operations in order.
-
Repeat the following operation until it can no longer be performed on any stone.
- If no stone is placed on the cell in the $i-1$-th row from the top and the $j$-th column from the left, move the stone on the cell in the $i$-th row from the top and the $j$-th column from the left to the cell in the $i-1$-th row from the top and the $j$-th column from the left.
-
Repeat the following operation until it can no longer be performed on any stone.
- If no stone is placed on the cell in the $i$-th row from the top and the $j-1$-th column from the left, move the stone on the cell in the $i$-th row from the top and the $j$-th column from the left to the cell in the $i$-th row from the top and the $j-1$-th column from the left.
Output the board after all the operations have been performed.
Constraints
- $1 \leq N, M \leq 100$
- $S_{i,j}$ is either
.or# - $N$, $M$ are integers
Input
$N\ M$ $S_1$ $S_2$ $\vdots$ $S_N$
Output
Print a newline at the end.
Sample
Sample 1
Input
2 2 .. .#
Output
#. ..
The board changes as follows with each operation.
.. .# #.
.# .. ..
Sample 2
Input
3 4 #### #### ####
Output
#### #### ####
Sample 3
Input
16 64 ........########....########....########....########....######## .......#########...#########...#.......#...#.......#...######### .......#########...#########...#.......#...#.......#...######### ......##########..##########..#........#..#........#..########## ......##########..##########..#........#..#........#..########## .....###########.###########.#.........#.#.........#.########### .....###########.###########.#.........#.#.........#.########### ....#########################..##......##..##......############# ....#########################..##......##..##......############# ...####.###########.########..#.#.........#.#......####.######## ...####.###########.########..#.#.........#.#......####.######## ..####..##########..#######..#..#........#..#.....####..######## ..####..##########..#######..#..#........#..#.....############## .####...#########...######..#...#.......#...#....####..######### .####...#########...######..#...#.......#...#....####..######### ####....########....########....########....########....########
Output
################################################################ ###############################################################. #####################################################........... ####################################################............ ###########################################..................... ##########################################...................... #########################################....................... ########################################........................ ##############################.................................. #############################................................... ##########################...................................... #########################....................................... ########################........................................ ########################........................................ #######################......................................... #######################.........................................
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
sepa38
くらげ