HigherMaze
TCI '02 Semifinals 1 · 2002-11-22 · by lars2520
Problem Statement
We all know that there are not necessarily three dimensions, and that there are wormholes scattered throughout the universe which will transport you through time and space. However, because it is often difficult for people to conceptualize higher dimensions, we will probably have to have computers do most of our navigation for us. Your task is to write a program that will simulate a pseudo-random asteroid field, and then navigate a ship through the asteroid field as quickly as possible.
The first step will be to generate the asteroid field. You will be given a
int current = 1;
for(int i0 = 0; i0<dim0; i0++)
for(int i1 = 0; i1<dim1; i1++)
... one loop per dimension
{
current = (current*a)%p;
if((current&1)==1){
//add an asteroid at (i0,i1,i2,...)
}
}
Once the asteroid field is generated, you have to navigate through it. You will be given a
..... .TTT. .TST. .TTT. .....
In addition to this type of movement, you may also (but are not required to) travel through wormholes. You will be given a
Sometimes, it will be impossible to reach finish from start. In this case return, 2^31-1 = 2147483647.
Constraints
- The product of all the elements of dim will be between 2 and 1000, inclusive.
- Each element of dim will be between 2 and 20, inclusive.
- dim will contain between 1 and 5 elements, inclusive.
- a and p will be between 1 and 2,000,000,000, inclusive.
- a times p will be between 1 and 2,000,000,000, inclusive.
- start and finish will be within the hyper-box defined by dim.
- start and finish will be both be empty space (not an asteroid, possibly a wormhole).
- wormholes will contain between 0 and 50 elements, inclusive.
- Each element of wormholes will be formatted as "
and will both be space delimited (no extra, leading or trailing spaces) lists of integers, representing a coordinate in space within the hyper-box defined by dim. and will both be empty space (not an asteroid). - There will be no way to go back in time infinitely. (In other words, there will be no reachable cycles that take negative amounts of time. However, there may be unreachable ones, but they can not affect the return, since they are unreachable.)
138
193
{5,5}
{0,0}
{4,4}
{}
Returns: 6
This input generates the following two dimensional asteroid field, where an 'X' is an asteroid, and a '.' is open space. (Here, (0,0) is the upper left corner, and (4,4) is the lower right, and (4,0) is in the lower left): ...XX XX.X. ..XXX ....X .XXX. Here is one path that takes 6 time units, where 'S' represents the start, 'F' the finish, and '*' the path. S*.XX XX*X. .*XXX ..**X .XXXF
138
193
{5,5}
{0,0}
{4,4}
{"0 0 2 4 4"}
Returns: 2
While there is still a path from (0,0) to (4,4) which takes 6 time units, there is also a wormhole, which transports you directly from (0,0) to (4,4), and ahead 2 units of time.
138
193
{5,5}
{0,0}
{4,4}
{"0 0 2 4 4","0 0 8 1 4","0 2 5 1 4","1 4 -8 4 4"}
Returns: -1
This is the same asteroid configuration as the previous two examples, but now there are more wormholes. The quickest way to get from (0,0) to (4,4) is to move from from (0,0) to (0,2), which takes 2 units of time. From (0,2) we should go through the wormhole to (1,4), which transports us ahead 5 units of time, for a total of 7. Then, we can take the wormhole from (1,4) to (4,4), which takes us back 8 units of time. Thus, the total time for the trip is 2 + 5 - 8 = -1, and we arrive before we left!(note that two wormholes can start at the same location, and could even start and end at the same location)
54
73
{20,20}
{1,2}
{12,12}
{}
Returns: 23
139
193
{20,20}
{0,2}
{18,19}
{"0 2 -100000 0 19","4 18 -100000 7 0","8 0 1000000 19 10","19 6 -800000 13 8"}
Returns: 21
The only way to get all the way is to go through all 4 wormholes, in order.
Submissions are judged against all 56 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class HigherMaze with a public method int navigate(int a, int p, vector<int> dim, vector<int> start, vector<int> finish, vector<string> wormholes) · 56 test cases · 2 s / 256 MB per case