Editorial for WC '18 Contest 2 S1 - Laser Grid
Submitting an official solution before solving the problem yourself is a bannable offence.
For convenience, let's pretend that there are two extra vertical lasers with values and , and similarly two extra horizontal lasers with values and . Then, let be the -coordinate of the nearest vertical laser to the left of Ethan (in other words, the largest value smaller than ). Similarly, let be the -coordinate of the nearest vertical laser to the right of Ethan (the smallest value larger than ), and let and be the -coordinates of the nearest horizontal lasers below and above Ethan, respectively. The values , , , and may be computed by iterating over all of the lasers' and values, in time.
We can then observe that the -th microchip is reachable if and only if and . This check can be performed in time per microchip, resulting in a total time complexity of .
Comments