Editorial for IOI '09 P6 - Mecho
Submitting an official solution before solving the problem yourself is a bannable offence.
Solution 1
Firstly, working with fractional amounts of time is tricky, so we will measure time in units of
Let us try to solve an easier problem first. Suppose we know when Mecho leaves the honey: can he get home safely? If we can solve this problem, then we can use it inside a binary search to find the last moment at which he can leave.
Mecho's moves will depend on the bees, but the bees' moves are fixed, so let us deal with the bees first. A standard breadth-first search will tell us when the bees reach each grassy cell (this just means simulating the spread of the bees over time).
Next, we can perform a similar breadth-first search for Mecho to answer the question "How soon (if at all) can Mecho reach each cell?" This can be implemented almost exactly as for the bees, except that one must exclude any steps that would have Mecho move to a cell where he would immediately be caught.
These breadth-first searches can each be implemented in
Solution 2
Instead of using a binary search, we can use a more complicated method to directly determine the optimal time to leave any cell. The bees are processed as in the first solution. However, instead of working from the honey towards Mecho's home, we start from his home. Since he is safe in his home, there is no limit on how late he can arrive there.
Now suppose we know that for some cell
One can now do a priority-first search: simulate backwards in time, keeping track of the latest time to leave each cell (keeping in mind that
The time complexity of this solution depends on the priority queue used to order cells by leaving time. A binary heap gives an
Comments