Editorial for WC '18 Contest 3 S3 - Counterpicking
Submitting an official solution before solving the problem yourself is a bannable offence.
For each Pokémon trainer , let . We can observe that this ratio is sufficient to determine which of Jessie's Pokémon is optimal to use against that trainer. We can furthermore observe that each of Jessie's Pokémon is either never optimal, or is optimal for a single interval of ratios.
Our objective will be to pre-process Jessie's set of Pokémon into a sequence of Pokémon and corresponding splitting points , such that is optimal for ratios in the interval , is optimal for ratios in the interval , and so on, with being optimal for ratios in the interval . If we can perform this pre-processing, then we'll be able to obtain the answer for each trainer in time by binary searching on for the interval containing , and using the corresponding optimal Pokémon.
Given two of Jessie's Pokémon and , let's consider when one is more optimal than the other. If , then whichever Pokémon has a larger value is simply always better. Otherwise, if we assume that and let , then the two Pokémon are equally optimal for the ratio , Pokémon is more optimal for all ratios smaller than , and Pokémon is more optimal for all ratios greater than .
Given that fact, let's sort Jessie's Pokémon in non-decreasing order of values and then iterate over them in that order, while ignoring any which are known to never be optimal (due to having an equal value to another Pokémon and a smaller value). As we go, we'll maintain our sequence of optimal Pokémon, which is initially empty. Each time we process a new Pokémon, we'll add it onto the end of , but first we may need to remove zero or more Pokémon from the end of if their intervals of optimal ratios have been rendered empty. For example, if the last two Pokémon in are and , we're currently processing Pokémon , and , then there is no ratio for which Pokémon is optimal, and it should be removed from .
Sorting Jessie's Pokémon takes time, and then processing them to generate the sequence takes another time. The sequence of splitting points may then be generated based on it in time, with for each . Finally, we can use this to compute the optimal answers for all of the Pokémon trainers as described above, bringing the total time complexity up to .
Comments