Editorial for COI '08 #1 Izbori


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 first subtask (finding the largest number of parliament seats for a party) is solved by simulation. For each party, we assume it receives all outstanding votes and then use the D'Hondt method to calculate the number of seats won. The time complexity is \mathcal O(S^2 \times M).

The second subtask is more difficult. The solution is based on dynamic programming and binary search.

For each party, we are asked to calculate the smallest number of seats it can win, assuming the least favourable distribution of remaining votes. Parties that initially have less than 5\% of votes can win zero parliament seats so it is not necessary to perform further calculations for them.

If the remaining votes can be distributed so that a party wins X seats, then they can also be distributed so that the party gets X+1 votes (up to the maximum calculated in the first subtask). We can use binary search to find the smallest such X, if we can answer the question "Is it possible to distribute the outstanding votes to other parties so that this party wins X or fewer seats?"

That question can be answered by a dynamic programming algorithm. The function f(P, S) is the least number of votes we need to add to parties up to and including P so that all of them would win S seats in the parliament. In the end, all parties involved in the allocation of seats must have received at least 5\% of all votes (meaning that at most 20 of them will be considered by the algorithm). The complexity of this DP check is about 20M^2 steps. There will be at most \log M checks for at most 20 parties, so the overall complexity is about (20 \log M)(20M^2).


Comments

There are no comments at the moment.