Diamonds
Time limit1sMemory limit128 MB
For each count Pmin, find the smallest radius whose worst-case center covers at least Pmin points, then the best coverage at that radius.
- Level
Medium6 of 10
- Topics
- Geometry, Prefix sum, Implementation, Brute force
- Solved
- No attempts yet
Problem
Consider a planar grid with rows and columns. It has exactly intersections, each identified by a coordinate pair with (the column, or -coordinate) and (the row, or -coordinate).
Now place points on distinct intersections.
A diamond is centred at intersection and is a square of diagonal length rotated ; its radius is any integer with . Equivalently, covers exactly the points whose Manhattan distance from the centre is at most , that is, every point with .
For each , find the smallest radius such that a diamond of that radius is guaranteed to cover at least points no matter which intersection its centre is placed on. In other words, is the smallest for which the worst case (the minimum, over all centres, of the number of covered points) is at least .
Let be the largest number of points that any single diamond of radius can cover.
For example, take five points at , , , , and on a grid of rows and columns. The diamond covers no point, covers one point, and covers four points.
Input
Line 1 contains the number of rows and the number of columns .
The remaining lines list the points (). Each point is given as a pair of integers: its -coordinate followed by its -coordinate. Points may be spread across one or more lines, and all values on a line are separated by one or more whitespace characters (spaces or tabs).
You may assume and . Any point lying outside the grid (that is, , , , or ) is invalid and must be discarded.
Output
Print a header line containing the three column titles Pmin, Rmin(Pmin), and Pmax(Pmin), then one line for each qualifying value of .
For a value of , output the triple , , only if a diamond of radius is guaranteed to cover exactly points. When two consecutive values share the same radius (for example ), only the larger one qualifies, so the smaller value produces no line.
Each value is right-aligned so that its last character lines up with the last character of that column's heading, and columns are separated by two spaces.