vision

Time limit: 1s Memory limit: 1024MB Input: Output:

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 (X,Y)(X,Y) there is a beacon with vision strength VX,YV_{X,Y}. When in that sector, the ship uses the beacon to scan all sectors (Xβ€²,Yβ€²)(X',Y') with Xβˆ’VX,Y≀X′≀X+VX,YX-V_{X,Y} \leq X' \leq X+V_{X,Y} and Yβˆ’VX,Y≀Y′≀Y+VX,YY-V_{X,Y} \leq Y' \leq Y+V_{X,Y}. Thus, the seen sectors form a square of side length 2VX,Y+12V_{X,Y}+1. For each such sector, the only information seen is the vision strength of the beacon in it, i.e. VXβ€²,Yβ€²V_{X',Y'} (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.

XX is row number (increasing in the down direction) and YY is the column number (increasing in the right direction).

Unfortunately, the beacons have one critical flaw: they may flip the XX axis of the scan, or the YY axis, or both (i.e. there are 44 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 YY axis is flipped and the ship teleports to the left direction (decreasing YY) 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 XX and YY arbitrarily far (we can say that we require it to eventually reach a sector (X,Y)(X,Y) such that X,Yβ‰₯10100X,Y \geq 10^{100}). 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 NN by MM rectangular pattern PP of vision strengths which will repeat infinitely across the universe: VX,Y=PXmod  N,Ymod  MV_{X,Y} = P_{X \mod N, Y \mod M} 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 PP.

Since this problem may seem quite challenging, you decide to start with a practice problem: the same problem but in 1D1D. In this simpler problem, we throw away the XX dimension and only use the YY one. Thus, your pattern is just a sequence of length MM and it is repeated like so: VY=PYmod  MV_Y = P_{Y \mod M}. The scans produced by beacons are also just sequences of length 2VY+12V_Y+1 (containing the sectors Yβ€²Y' such that Yβˆ’VY≀Y′≀Y+VYY-V_Y \leq Y' \leq Y+V_Y). Here, there are only 22 possible orientations for the scan (regular or flipped) and the ship must be able to reach Yβ‰₯10100Y \geq 10^{100}.

Your solutions for the 1D1D case and the 2D2D 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 44 functions: getVisionPattern1d, getMove1d, getVisionPattern2d and getMove2d. The first 22 are used for the 1D1D case and the second 22 – for the 2D2D one. In any test only one of these pairs of functions will be called, but all 44 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 1D1D case. It must return a the sequence PP of length MM – the 1D1D vision strength pattern to be repeated. MM and all elements of PP must be between 11 and 6060.

int getMove1d(std::vector<int> v)

This function will be called once per possible scan, if the test is for the 1D1D case. It is given a scan produced by a beacon, as a sequence of length 2V+12V+1 (where VV 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 TT in the sequence, such that 0≀T<2V+10 \leq T < 2V+1.

std::vector<std::vector<int>> getVisionPattern2d()

This function will be called once, if the test is for the 2D2D case. It must return a rectangular table PP of size NN by MM – the 2D2D vision strength pattern to be repeated. NN, MM and all elements of PP must be between 11 and 6060.

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 2D2D case. It is given a scan produced by a beacon, as a square table of size 2V+12V+1 by 2V+12V+1 (where VV 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 SS and TT in the table, such that 0≀S,T<2V+10 \leq S,T < 2V+1.

For the given dimensionality DD (11 or 22) 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

  • 1≀D≀21 \leq D \leq 2
  • 1≀N,M,VX,Y,VY≀601 \leq N,M,V_{X,Y},V_Y \leq 60
Subtask Points DD Aβˆ—A*
1 24 11 1.51.5
2 76 22 1.1251.125

Your score for a given subtask (if your solution for it is correct) depends on the average vision strength in your pattern PP for it. Let that be AA and let the target for the subtask be Aβˆ—A*. Your score (fraction of points for the subtask) will be:

1βˆ’(1βˆ’Aβˆ—βˆ’1max⁑(A,Aβˆ—)βˆ’1)0.81-(1-\frac{A*-1}{\max(A,A*)-1})^{0.8}

Sample pattern

Suppose your solution returns the following pattern with N=3N=3 and M=2M=2:

[123456]\begin{bmatrix} 1 & 2 \\ 3 & 4 \\ 5 & 6 \end{bmatrix}

Now, let’s examine the possible scans at sector (0,1)(0, 1), which has vision strength 22. There are 44 possible orientations (some of which produce the same scan on this pattern):

Orientation 00: No flips

[4343465656212124343465656]\begin{bmatrix} 4 & 3 & 4 & 3 & 4 \\ 6 & 5 & 6 & 5 & 6 \\ 2 & 1 & 2 & 1 & 2 \\ 4 & 3 & 4 & 3 & 4 \\ 6 & 5 & 6 & 5 & 6 \end{bmatrix}

Orientation 11: YY-axis flipped

[4343465656212124343465656]\begin{bmatrix} 4 & 3 & 4 & 3 & 4 \\ 6 & 5 & 6 & 5 & 6 \\ 2 & 1 & 2 & 1 & 2 \\ 4 & 3 & 4 & 3 & 4 \\ 6 & 5 & 6 & 5 & 6 \end{bmatrix}

Orientation 22: XX-axis flipped

[6565643434212126565643434]\begin{bmatrix} 6 & 5 & 6 & 5 & 6 \\ 4 & 3 & 4 & 3 & 4 \\ 2 & 1 & 2 & 1 & 2 \\ 6 & 5 & 6 & 5 & 6 \\ 4 & 3 & 4 & 3 & 4 \end{bmatrix}

Orientation 33: Both axis flipped

[6565643434212126565643434]\begin{bmatrix} 6 & 5 & 6 & 5 & 6 \\ 4 & 3 & 4 & 3 & 4 \\ 2 & 1 & 2 & 1 & 2 \\ 6 & 5 & 6 & 5 & 6 \\ 4 & 3 & 4 & 3 & 4 \end{bmatrix}

Since 00 and 11 are identical and since the ship is deterministic, only one call to getMove2d will be made for them. Suppose your solution returns the move (0,1)(0, 1) on this scan. On orientation 00 this would mean moving 11 to the left and 22 up, while on orientation 11 – moving 11 to the right and 22 up.

Sample grader

The sample grader’s first input is DD. After that it will do all calls to your function: first getting the pattern PP 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 (00 for no flips, 11 to flip the YY axis, 22 to flip the XX axis and 33 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.

Log in or sign up to be able to send submissions!