아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Gravity

면접 대비

시간 제한1.5초메모리 제한256 MB

요약
4방향으로 연결된 '#' 묶음을 하나의 강체로 보고, 모든 조각을 같은 속도로 바닥까지 떨어뜨려 바닥이나 다른 조각 위에 멈춘 최종 상태를 출력한다.
난이도

보통10점 중 5점

유형
시뮬레이션, 그래프, DFS, 구현
정답자
아직 제출이 없습니다

문제

You are given an N×MN \times M binary matrix. Cell (i,j)(i, j) contains the character "." if it is free and the character "#"' if the cell is occupied by a piece. Each maximal 4-connected component of "#" characters forms an indivisible piece. During the process described below, the pieces do not merge or split in any way. All cells that are part of the same piece will move in exactly the same way.

The pieces start falling towards the floor (the last row of the matrix) with equal speeds. The pieces move down without any rotations. Every second, all pieces try to move down one row. If this motion results in a piece crossing the lower boundary of the matrix, that piece stops in place instead. Similarly, if this motion results in a piece overlapping with another piece (note that this can only happen if the latter piece is not moving), then the former piece also stops in place. In other words, pieces stop falling when they hit the floor or when they hit another piece.

Output the final state of the pieces after all of them stop falling.

입력

The first line of input contains two integers NN and MM (1≤N,M≤20001 \le N, M \le 2000).

The next NN lines describe the matrix. Each of them contains MM characters which are either "." or "#". The characters denoting cells on the same line are not separated by any whitespace.

출력

Print the resulting matrix after all pieces have finished falling. The matrix must be printed in the same format as given in the input, except for the line containing the matrix dimensions.

예제1

  1. 예제 1

    입력
    10 10
    ..........
    ..######..
    ..#....#..
    ..#.#..#..
    ..#..#.#..
    ..#....#..
    ..######..
    ..........
    ..#....#..
    .......#..
    
    예상 출력
    ..........
    ..........
    ..######..
    ..#....#..
    ..#....#..
    ..#....#..
    ..#.##.#..
    ..######..
    .......#..
    ..#....#..