Editorial for WC '18 Contest 3 S4 - Holey Travels


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.

There must always exist an optimal circle which is tangent to at least one trainer i'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 i 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 i and one of its sides, the set of possible circle centers forms a line c running parallel to line i, R units away from it. We'll compare this line c against each trainer j's line:

  • If line j is parallel to line c, then a circle centered anywhere on line c will either always or never intersect with line j, depending on whether the distance between those two lines is greater than R. Let a be the sum of P values corresponding to all such lines j which will always be intersected (note that these always include line i itself).
  • Otherwise, if line j is not parallel to line c, then there exists a single interval of circle centers along line c for which the circle will intersect with line j. This interval is centered at the intersection of lines c and j, and its boundaries may be computed with some trigonometry. In particular, we'll want to imagine that line c 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 c is then equal to a plus the sum of P 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 c.

For a given line c, comparing it to all of the trainers' lines takes \mathcal O(N) time, and then performing a line sweep on the resulting intervals takes \mathcal O(N \log N) time. We'll repeat this whole process twice for each trainer i'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 \mathcal O(N^2 \log N).


Comments

There are no comments at the moment.