Sirtet
InterviewTime limit2sMemory limit512 MB
Connected groups of filled cells fall straight down as rigid objects until each lands on the bottom row or on another object. Print the final grid.
- Level
Medium5 of 10
- Topics
- Simulation, BFS, Sorting
- Solved
- No attempts yet
Problem
In the zero-player video game Sirtet, the game takes place on a rectangular grid with rows and columns. Before the game begins, some cells are blank (.) and others are filled (#). Filled cells that are adjacent horizontally or vertically belong to the same rigid object. For example, this initial grid:
..#.
##.#
.##.
#...
#...
has four objects, shown below:
## # # #
## #
When the game begins, the objects fall straight down the grid, all at the same speed. Each object keeps falling until it either touches the bottom row or has some part land directly on top of another object, at which point it stops. What will be the final state of the grid?
Input
The first line contains two space-separated positive integers and ().
The following lines contain characters each, describing the initial state of the grid. If the -th column of the -th row contains a block, the corresponding character is #. Otherwise it is ..
Output
Output lines of characters each, describing the final state of the grid. If the -th column of the -th row contains a block, the corresponding character is #. Otherwise it is ..