問題一覧 > 通常問題

No.3657 Gathering Stones

レベル : / AI推定難易度 : 151 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 94
作問者 : sepa38 / テスター : dyktr_06 t5ugu くらげ
お気に入りにしたユーザー ProblemId : 13926 / 自分の提出
問題文最終更新日: 2026-08-30 01:57:02
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.

  1. 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.
  2. 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もしくは右上の雲マークをクリックしてアカウントを作成してください。