SlashPath
2019 Beijing Round · 2019-06-14 · by misof
Problem Statement
A slash maze is a rectangular table of characters, each being either a slash or a backslash. Example:
\\/\/ \\//\ \//\/ \\/\\
Each character represents a square cell with penetrable walls but an impenetrable diagonal wall. The entrance to the maze is always on the leftmost unit segment of the top side, and the exit is always on the rightmost unit segment of the bottom side. Thus, the slashes shown above correspond to the following maze:
You start outside of the maze and you must end outside of the maze. Entering the maze takes one step, and leaving the maze takes one step. In each other step you can move from your current triangle across the side of a square into an adjacent triangle. The above figure shows a 17-step path through the maze.
You are given the
- the number of rows is between 1 and 50, inclusive
- the number of colums is between 1 and 50, inclusive
- steps is exactly equal to the smallest number of steps needed to cross the maze from start to finish
Return the maze as a
Constraints
- steps will be between 1 and 3000, inclusive.
7
Returns: {"\\\\/\\", "/\\\\\\", "\\\\\\\\" }
A nicer formatting for the returned maze: \\/\ /\\\ \\\\ (Note that in all example outputs the backslashes in strings are escaped: each \\ represents a single backslash.)
17
Returns: {"\\\\/\\/", "\\\\//\\", "\\//\\/", "\\\\/\\\\" }
The example from the problem statement. The return value shown above corresponds to the figure in the statement.
1234
Returns: { }
1
Returns: { }
2
Returns: { }
Submissions are judged against all 126 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SlashPath with a public method vector<string> construct(int steps) · 126 test cases · 2 s / 256 MB per case