Connection Status:
Competition Arena > GravityPuzzleEasy
SRM 724 · 2017-11-27 · by cgy4ever · Simulation
Class Name: GravityPuzzleEasy
Return Type: String[]
Method Name: solve
Arg Types: (vector<string>)
Problem Statement

Problem Statement

We have a rectangular board divided into unit square cells. The board is mounted on a wall, with rows going horizontally and columns vertically. Each cell contains at most one box. You are given the current state of the board in the String[] board. The elements of board describe the rows of the board from top to bottom. (I.e., board[0] describes the topmost row of the board, and so on.) The characters of board[r] describe the cells in row r from left to right, with '.' being an empty cell and '#' a cell with a box.

Due to gravity, each box will fall down: whenever a cell below a box is empty, the box can fall into that cell. Thus, if you have a column with k boxes, those will eventually occupy the bottommost k cells in that column.

Please return a String[] describing the state of the board after all boxes finish falling down.

Constraints

  • board will contain between 1 and 50 elements, inclusive.
  • Each element in board will contain between 1 and 50 characters, inclusive.
  • Each element in board will contain the same number of characters.
  • Each character in board will be '.' or '#'.
Examples
0)
{"#",
 ".",
 "."}
Returns: {".", ".", "#" }

This box will fall to the bottom, so we get: . . #

1)
{"##",
 ".#",
 "#."}
Returns: {"..", "##", "##" }

This time we have 2 boxes in each column.

2)
{"..#.#",
 "#.#..",
 "...##"}
Returns: {".....", "..#.#", "#.###" }
3)
{"#####",
 "#####",
 "#####",
 "#####"}
Returns: {"#####", "#####", "#####", "#####" }
4)
{"."}
Returns: {"." }

Submissions are judged against all 72 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class GravityPuzzleEasy with a public method vector<string> solve(vector<string> board) · 72 test cases · 2 s / 256 MB per case

Submitting as anonymous