GravityBomb
SRM 200 · 2004-06-21 · by antimatter
Problem Statement
Tetris is one of those games that is everywhere; there aren't too many people who haven't seen it in some form or another since its conception in 1985. The concept is fairly simple. You have a vertically-oriented rectangular grid. Pieces, which are made up of some number of 1x1 blocks, fall downwards. Whenever an entire row of the grid is full of blocks, all of the blocks in that row disappear and all the pieces above are shifted downwards by a row.
TopCoder member antimatter is not very good at Tetris. The pieces drop too fast, he says. He's been toying with the idea of coding his own version, with one twist: the addition of the Gravity Bomb, which does not appear on the board. When the Gravity Bomb is activated, if any block is immediately above an empty space, it falls into that space. This process is repeated until there are no more blocks immediately above empty spaces. Then, any completed row of blocks will be removed and the blocks above them shifted downwards, until there are no more complete rows.
The board has a fixed width and height, and the initial state of the board will be represented as a
Constraints
- board will contain between 1 and 50 elements, inclusive
- each element of board will contain between 1 and 50 characters, inclusive
- each element of board will be the same length
- each character in board will be either 'X' or '.'
{"..X",
"X.X",
".X."}
Returns: { "...", "...", "..X" }
After the Gravity Bomb is used, the board looks like this: ... ..X XXX Then we remove the completed line at the bottom and move all blocks above downwards.
{"...",
"X..",
".X."}
Returns: { "...", "...", "XX." }
Here there are no complete lines.
{"XXXXXX",
"......",
"......"}
Returns: { "......", "......", "......" }
{"XX.XX....XX"}
Returns: { "XX.XX....XX" }
{"X",".",".",".",".",".",".",".",".",".",".",".",".",
".",".",".",".",".",".",".",".",".",".",".",".",".",
".",".",".",".",".",".",".",".",".",".",".",".",".",
".",".",".",".",".",".",".",".",".",".","."}
Returns: { ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", ".", "." }
Submissions are judged against all 47 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class GravityBomb with a public method vector<string> aftermath(vector<string> board) · 47 test cases · 2 s / 256 MB per case