SimpleMaze
SRM 723 · 2017-11-17 · by cgy4ever
Problem Statement
- Each cell is either empty ('.') or contains an obstacle ('#').
- The number of empty cells is finite.
- All empty cells form one 4-connected component (explained below).
- All obstacles form one 4-connected component.
We can describe a simple maze by describing the boundary between the empty cells and obstacles. You are given this description in the
Take a pen and place it anywhere onto the infinite plane.
For each i from 0 to length(moves)-1:
If i is even:
Move the pen moves[i] steps to the right.
Else:
Move the pen moves[i] steps upwards.
Note that some elements of moves will be negative. These correspond to movement to the left or downwards, respectively. For example, if moves = {3, 1, -2, 2, -1, -3} then the maze will look as follows:
##### #.### #.### #...# #####
(All other cells in the infinite plane are obstacles. We started drawing the boundary from the bottom left corner of the empty area.)
It is guaranteed that moves will always describe a closed polyline that never touches or intersects itself.
The distance between two empty cells is the smallest number of steps needed to get from one of the cells into the other.
You are given the
Constraints
- moves will contain between 4 and 2,000 elements, inclusive.
- moves will contain an even number of elements.
- For each valid i, 1 <= |moves[i]| <= 1,000,000.
- moves will describe a closed polyline that never touches or intersects itself.
{1,1,1,1,-1,1,-1,-1,-1,-1,1,-1}
Returns: 16
The maze looks like this: #.# ... #.#
{10,10,-10,-10}
Returns: 33000
The empty space is an empty square with side length 10.
{1,3,1,-3,2,1,1,-1,1,2,-2,1,2,1,-6,-4}
Returns: 629
...... .#..## .#.... .#..#.
{3,1,-2,1,1,1,-1,1,1,1,1,1,-3,-6}
Returns: 237
... ..# .## ..# .## ...
{-2,-2,-1,-3,-1,1,-1,2,-1,2,-2,-2,-1,-2,-1,-1,-1,3,-1,2,-9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,2,-1,1,-2,-4,9,-3,-7,-6,-1,-3,2,2,1,2,1,1,1,1,1,-1,1,-1,1,-5,-1,-1,-1,-1,-1,3,1,3,-1,-1,-1,-3,-1,-1,-1,-1,-2,1,-1,2,-1,3,1,2,1,4,-2,9,1,1,2,-1,1,-2,1,1,1,1,1,1,1,1,1,5,-2,1,-2,1,-2,1,-3,2,3,1,3,2,-3,1,-3,2,3,1,2,1,2,1,3}
Returns: 516034
############################################# ####...######.........##########..####..##### ##.......####...####...#########..####..##### #...###.........####...#########..####..##### #...#########...###...#########....##....#### ##....#######...#...###########....##....#### ###.....#####...##...#########..#..##..#..### ######...####...###...########..##....##..### #...###...###...####...######...##....##...## ##.......####...#####...#####..####..####..## ###.....#####...######.........####..####..## #############################################
{1000000,1000000,-1000000,-1000000}
Returns: 333218986
Don't forget mod.
Submissions are judged against all 122 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SimpleMaze with a public method int findSum(vector<int> moves) · 122 test cases · 2 s / 256 MB per case