FillInTheMaze
SRM 757 · 2019-04-28 · by misof
Problem Statement
There is a very simple way to draw mazes using ASCII characters. One sample maze with three entrances is shown below. (The '#'s represent walls, the '.'s represent empty cells.)
#######.##### ......#.#...# #.###.#.#.#.# #.#.......#.# #.#######.#.# #.......#.#.# #########.###
Here is the construction of such a maze in more detail. Let's take a look at an unfinished maze that has walls everywhere.
############# #.#.#.#.#.#.# ############# #.#.#.#.#.#.# ############# #.#.#.#.#.#.# #############
Rows and columns of the bitmap are numbered starting from 0 in the top left corner. Notice that the cells with both coordinates odd are still empty. These cells are called rooms. The cells that share a side with a room are called hallways and the remaining cells are called pillars. Hence, pillars have both coordinates even. Pillars will always be walls. Some hallways will eventually be empty while others will be walls.
You are given
- Each room must be reachable from each other room, without leaving the maze.
- There have to be exactly X exits (i.e., empty hallways on the boundary of the maze).
- The total number of wall cells ('#' characters) must be maximized.
Return a
Constraints
- R will be between 1 and 24, inclusive.
- C will be between 1 and 24, inclusive.
- X will be between 1 and 2R+2C, inclusive.
3
6
3
Returns: {"#######.#####", "......#.#...#", "#.###.#.#.#.#", "#.#.......#.#", "#.#######.#.#", "#.......#.#.#", "#########.###" }
These dimensions correspond to the examples in the problem statement. The maze shown in the statement is indeed one of the optimal solutions.
1
3
2
Returns: {"#######", ".......", "#######" }
A very simple maze with just one row of rooms and with two exits.
2
2
8
Returns: {"#.#.#", ".....", "#.###", ".....", "#.#.#" }
The returned maze: #.#.# ..... #.### ..... #.#.# Notice the one hallway that remained a wall. An answer without that wall would not be accepted, as the number of '#'s would not be as large as possible.
1
1
1
Returns: {"#.#", "#.#", "###" }
1
1
2
Returns: {"#.#", "..#", "###" }
Submissions are judged against all 61 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class FillInTheMaze with a public method vector<string> filled(int R, int C, int X) · 61 test cases · 2 s / 256 MB per case