Editorial for WC '18 Contest 3 S4 - Holey Travels
Submitting an official solution before solving the problem yourself is a bannable offence.
There must always exist an optimal circle which is tangent to at least one trainer 's line (it can't be better to choose a circle tangent to no lines, as it can always be shifted until it is tangent to one). We'll consider each possible line to place the circle tangent to. Given such a line, the circle can then lie on either of the two sides of the line, and we'll consider both possible sides.
Given a line and one of its sides, the set of possible circle centers forms a line running parallel to line , units away from it. We'll compare this line against each trainer 's line:
- If line is parallel to line , then a circle centered anywhere on line will either always or never intersect with line , depending on whether the distance between those two lines is greater than . Let be the sum of values corresponding to all such lines which will always be intersected (note that these always include line itself).
- Otherwise, if line is not parallel to line , then there exists a single interval of circle centers along line for which the circle will intersect with line . This interval is centered at the intersection of lines and , and its boundaries may be computed with some trigonometry. In particular, we'll want to imagine that line is a number line (with an arbitrary origin), and represent each interval's start and end points as scalar points along it.
The number of Pokémon trapped by centering the circle at a given point along line is then equal to plus the sum of values corresponding to all intervals overlapping with that point. The maximum possible value of this expression can be found by performing a line sweep along line .
For a given line , comparing it to all of the trainers' lines takes time, and then performing a line sweep on the resulting intervals takes time. We'll repeat this whole process twice for each trainer 's line (once per side) to determine the maximum number of Pokémon which can be trapped by any possibly optimal circle, bringing the total time complexity up to .
Comments