KoddiOA #4
Count 2x2 Submatrices by Black Cell Count
Estimated MediumJudge-ready
Topics (AI-labelled)Hashing
Given the coordinates of all black cells in a rows×cols grid. Classify each 2×2 submatrix by the number of black cells it contains, 0..4, count each class, and return the five counts. Coordinates start from 0 and contain no duplicates.
The statement is explicit; this site adds the coordinate ranges, the distinctness of black cells, and the input protocol.
Input
The first line contains rows cols k (1≤rows,cols≤10^9, 0≤k≤min(rows×cols,200000)); the next k lines give the 0-based row col of each black cell.
Output
Output 5 integers: the numbers of windows containing 0, 1, 2, 3, and 4 black cells, in that order.
Example 1
Input:
3 3 2
0 0
1 1
Output:
0 3 1 0 0
Example 2
Input:
1 5 0
Output:
0 0 0 0 0
Example 3
Input:
2 2 4
0 0
0 1
1 0
1 1
Output:
0 0 0 0 1
Editorial
Loading solution…