Editorial for BPC 1 S2 - Train Commute
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Hint
Subtask 1
This subtask was meant to reward all kinds of binary search solutions and linear solutions that use more than
Finding the position of any station when none of the stations are known can be hard.
Therefore, we start by binary searching for the positions of the first and last stations.
To do so, we first calculate ? 0 C
to get the total amount of time saved by using the train as opposed to walking all the way from
After we have the position of the leftmost station, we can do some other type of binary search for each subsequent station. For example, we could take a station and binary search to its right for the smallest position where we can get to it faster than walking. This will be roughly halfway between the current and next station and we can use the result of the final query to determine the exact location of the next station.
Number of queries:
Hint
If we have determined that there are stations at positions
Subtask 2
If we know there are stations at positions
To fully solve the problem, we can use binary search to find the first and last stations.
Then we repeatedly use the strategy of querying midpoints on intervals that have not yet been queried.
We do this until we have queried the midpoint of every pair of adjacent stations.
This can be implemented with recursion or a queue.
After the binary search, this solution will use at most
Number of queries:
Comments