Gravity
면접 대비시간 제한1.5초메모리 제한256 MB
4방향으로 연결된 '#' 묶음을 하나의 강체로 보고, 모든 조각을 같은 속도로 바닥까지 떨어뜨려 바닥이나 다른 조각 위에 멈춘 최종 상태를 출력한다.
문제
You are given an binary matrix. Cell 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 and ().
The next lines describe the matrix. Each of them contains 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.