Editorial for TLE '17 Contest 4 P4 - Willson and Target Practice

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.

Author: d

For the first subtask, the triangle can contain at most 2 points. These points are horizontally adjacent. That is, for any pair (x,y), the triangle can contain (x,y) and (x+1,y).

There are 4001^2 possible coordinates, so we can store an array of size 4001^2, iterate through all possible triangles, find the best (x,y), and output the answer.

Time Complexity: \mathcal{O}(N + (\max |c|)^2), but \mathcal{O}(N \log N) is possible too.

For the second subtask, we want to check if there is a triangle that can contain both points. We look at the first point, and colour in the possible locations of the second point. This region forms a regular hexagon that is centered at the first point and has side length K.

If the hexagon contains the second point, the answer is 2. Otherwise, the answer is 1. Determining if the second point lies in the hexagon is left as an exercise to the reader.

Note: Unfortunately, the test data for this subtask is weak, and a naive implementation is able to pass.

Time Complexity: \mathcal{O}(1)

An explanation for subtask 3 is a work in progress.

Subtask 4 is intended to reward submissions that could not pass subtask 5.

First, let's make the problem simpler.

We need to find the answer for upward triangles and downward triangles. Let's find the answer for downward triangles. To do this, flip the y coordinates, then find the answer for upward triangles.

As a result, we'll need to find the answer for upward triangles on 2N points. Obviously, the first N points should be far away from the last N points. Let's find the answer for upward triangles.

All upward triangles are completely determined by a coordinate. This is now a problem of finding the maximal coordinate(s) (i.e. if an upward triangle is placed here, it would achieve the maximum number of targets).

If (x,y) is a maximal coordinate, then (x,\lceil y \rceil) is also a maximal coordinate. Therefore, we only need to search through integer y coordinates to find a maximal coordinate.

The number of reasonable choices for y is \mathcal{O}(\max |c|). In all other choices of y, the coordinate will never hit a target. Therefore, we only need to search through \mathcal{O}(\max |c|) different y's to find a maximal coordinate.

Let's search through a choice of y. A target will either do nothing, or create a line segment (i.e. if an upward triangle is placed anywhere on this line segment, then it will contain the target). Then do some difference array stuff to find the point that hits the most targets. (Note: This point could be at the endpoint of a line segment. It's easy to account for this. If a line segment is the interval [a,b], it's enough to change this to [a-10^{-5},b+10^{-5}].)

Note that \mathcal{O}(KN) line segments are created. If you want, you could precompute these line segments in \mathcal{O}(KN) time.

Time Complexity: \mathcal{O}(KN \log N), but \mathcal{O}(N^2+KN \log N) should pass too.


There are no comments at the moment.