Editorial for WC '16 Contest 4 S1 - Parking Duty


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

If no meters were to be skipped, then Judy's day would consist of N-1 "legs", with the i-th leg consisting of travelling from coordinates (X_i, Y_i) to (X_{i+1}, Y_{i+1}) in T_{i+1}-T_i seconds. The minimum top speed required to complete such a leg is simply the Euclidean distance of the leg divided by the time allowed for it. As such, the minimum top speed required for the entire day would be equal to the maximum of the N-1 legs' required top speeds.

In reality, the day will only have N-2 legs, as one meter will be skipped. If some meter i is chosen to be skipped, aside from the first or last (such that 1 < i < N), then legs i and i+1 will be removed and replaced by a new leg that travels directly from meter i to i+2 (whose required top speed can be computed in the same way). If the first or last meter is skipped, then the first or last leg will instead be removed and not replaced with any new one.

At any rate, it can be observed that at most 2 of the original N-1 legs can be removed, with the others staying as they are. Furthermore, if the original leg with the largest required top speed is the i-th one (in the case of ties, i can be any leg with the maximum required top speed), then in order to even have a chance of reducing the answer, the i-th leg must be one of the ones removed. Therefore, once we determine the index i (which can be done in \mathcal O(N) time), we only need to consider skipping either meter i or i+1, and for each of those two options, we can afford to simulate the entire day with the given meter skipped in \mathcal O(N) time, once again calculating the required top speeds of all N-2 legs present and taking the largest of them. Finally, the answer will be the smaller of the two required top speeds yielded by the two possibly optimal options.


Comments

There are no comments at the moment.