The USS Enterprise spaceship (with Sashka as its new captain) is traveling throughout the universe, which is an infinite 2D grid of sectors. In each sector there is a beacon with vision strength . When in that sector, the ship uses the beacon to scan all sectors with and . Thus, the seen sectors form a square of side length . For each such sector, the only information seen is the vision strength of the beacon in it, i.e. (this is because beacons act as both transmitters and receivers). After scanning, the ship then teleports to one of these seen sectors, as beacons also act as teleporters.
is row number (increasing in the down direction) and is the column number (increasing in the right direction).
Unfortunately, the beacons have one critical flaw: they may flip the axis of the scan, or the axis, or both (i.e. there are possible scan orientations). Notice that the ship uses this possibly flipped scan to decide which sector to teleport to, but the teleportation also uses the same orientation, e.g. if the axis is flipped and the ship teleports to the left direction (decreasing ) of the scan, it will actually teleport to the right. This means that the ship will indeed teleport to sector chosen in the scan.
Furthermore, the ship has no memory, so its decision on where to teleport to must depend only on the scan produced by the beacon. Additionally, the shipβs strategy must be deterministic β if given the same scan, it must choose to teleport to the same sector in the scan.
The ship starts at unknown coordinates and must always (regardless of where it starts and regardless of what orientations of scans it gets) be able to travel in the direction of increasing and arbitrarily far (we can say that we require it to eventually reach a sector such that ). However, for this to be possible, both the travel strategy of the ship and the layout of vision strengths across the universe are crucial.
This is where you come in β you have to design an by rectangular pattern of vision strengths which will repeat infinitely across the universe: You also have to design the travel strategy for the ship, i.e. a function which takes in the scan produced by the beacon and chooses to which of those sectors to teleport to next.
Since beacons with higher vision strength are expensive, your goal is to produce a valid solution, while trying to minimize the average vision strength in your pattern, i.e. the average value of .
Since this problem may seem quite challenging, you decide to start with a practice problem: the same problem but in . In this simpler problem, we throw away the dimension and only use the one. Thus, your pattern is just a sequence of length and it is repeated like so: . The scans produced by beacons are also just sequences of length (containing the sectors such that ). Here, there are only possible orientations for the scan (regular or flipped) and the ship must be able to reach .
Your solutions for the case and the case will be scored separately and you may get points for one without having a valid solution for the other.
Implementation details
You have to implement functions: getVisionPattern1d, getMove1d, getVisionPattern2d and getMove2d. The first are used for the case and the second β for the one. In any test only one of these pairs of functions will be called, but all must be implemented (even if the implementations for one pair are empty) for the solution to be valid (to compile).
std::vector<int> getVisionPattern1d()
This function will be called once, if the test is for the case. It must return a the sequence of length β the vision strength pattern to be repeated. and all elements of must be between and .
int getMove1d(std::vector<int> v)
This function will be called once per possible scan, if the test is for the case. It is given a scan produced by a beacon, as a sequence of length (where is the vision strength of the beacon in the central sector in the sequence). It must return which sector the ship should teleport to, as an index in the sequence, such that .
std::vector<std::vector<int>> getVisionPattern2d()
This function will be called once, if the test is for the case. It must return a rectangular table of size by β the vision strength pattern to be repeated. , and all elements of must be between and .
std::pair<int, int> getMove2d(std::vector<std::vector<int>> v)
This function will be called once per possible scan, if the test is for the case. It is given a scan produced by a beacon, as a square table of size by (where is the vision strength of the beacon in the central sector in the square). It must return which sector the ship should teleport to, as a pair of indices and in the table, such that .
For the given dimensionality ( or ) of the test, the grader will check that your program produces a valid pattern β that it makes valid teleportation choices for all possible scans and that your solutions works regardless of starting coordinates and sequence of orientations of scans.
Constraints and clarifications
| Subtask | Points | ||
|---|---|---|---|
| 1 | 24 | ||
| 2 | 76 |
Your score for a given subtask (if your solution for it is correct) depends on the average vision strength in your pattern for it. Let that be and let the target for the subtask be . Your score (fraction of points for the subtask) will be:
Sample pattern
Suppose your solution returns the following pattern with and :
Now, letβs examine the possible scans at sector , which has vision strength . There are possible orientations (some of which produce the same scan on this pattern):
Orientation : No flips
Orientation : -axis flipped
Orientation : -axis flipped
Orientation : Both axis flipped
Since and are identical and since the ship is deterministic, only one call to getMove2d will be made for them. Suppose your solution returns the move on this scan. On orientation this would mean moving to the left and up, while on orientation β moving to the right and up.
Sample grader
The sample graderβs first input is . After that it will do all calls to your function: first getting the pattern and then caching all teleportation choices. After that, it will start a console interaction, asking for the starting coordinates of the ship. After that, it will print the current state: coordinates and βrawβ (without flips) scan. Then, it will ask for the orientation to be used ( for no flips, to flip the axis, to flip the axis and to flip both). After that, it will print the scan in the given orientation, as well as what move the ship choose. The ship will be moved and this will repeat. Notice that the sample grader will not automatically verify that your solution is correct.