Neighbours
Time limit2sMemory limit64 MB
Given n peaks on a w by h grid, count non-peak grid points by how many of their four axis directions contain a peak.
- Level
Medium7 of 10
- Topics
- Sorting, Hash map, Implementation, Prefix sum
- Solved
- No attempts yet
Problem
The Great Bytean Mountains occupy a rectangle in the Cartesian plane whose opposite corners are and , where and are positive integers. Inside the rectangle there are mountain peaks, each located at a grid point (a point with integer coordinates).
Tourists want to build houses on grid points. The park rules are strict: at most one house may stand on each grid point, and no house may be built on a peak. There are therefore possible house locations.
Some locations are better than others. A grid point that is not a peak has a northern neighbour if there is a peak at for some positive integer . Southern, eastern, and western neighbours are defined analogously — a peak in the same column below it, or in the same row to its east or west. Every non-peak grid point thus has between and neighbours, and the more neighbours it has, the better the view.
Count how many non-peak grid points have exactly , , , , and neighbours.
Input
The first line contains three integers , , and (, ), separated by single spaces. Each of the following lines contains two integers and (, ), separated by a single space, giving the location of one peak. All peaks are at distinct grid points.
Output
Print five integers separated by single spaces: the numbers of non-peak grid points that have exactly , , , , and neighbours, in that order.
Note
In the example, the non-peak points with exactly two neighbours are and ; those with three neighbours are , , and ; the point has four neighbours; the point has none; and every remaining non-peak point has exactly one neighbour.