Editorial for IOI '00 P2 - Car Parking


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.

The final state of the parking center can easily be determined by sorting the input list of car types. This can be done in linear time (\mathcal O(M+N)). \mathcal O(N^2) and \mathcal O(N \log N) methods may be too slow for larger N.

A greedy approach to construct successive rounds will work, since in each round it can be guaranteed that at least W-1 cars are put into their final position. Hence, the number of rounds needed by this greedy algorithm is \left\lceil \frac{D}{W-1} \right\rceil, where D is the number of displaced cars in the initial state for the input. In general, finding the minimum number of rounds is NP-complete. Even reducing the number of rounds for the greedy algorithm by just one round is, in general, as hard as finding the minimum (compare to bin packing: you need to find cycles that add up in length to W, for otherwise one worker is not doing useful work).

The greedy algorithm can be implemented in \mathcal O(N+M) space and \mathcal O(N) time. However, a more naive implementation may use \mathcal O(N) space and \mathcal O(N^2) time. The test data has been designed to distinguish linear solutions from less efficient ones.


Comments

There are no comments at the moment.