For a grid of black and white cells with rows rows and cols columns, you’re given an array black that contains the [row, column] coordinates of all the black cells in the grid.
Your task is to compute how many 2 x 2 submatrices of the grid contain exactly blackCount black cells, for each 0 <= blackCount <= 4. As a result, you will return an array of 5 integers, where the i-th element is the number of 2 x 2 submatrices with exactly i black cells.
It is guaranteed that black cell coordinates in the black array are pairwise unique, so the same cell is not colored twice.
Example
For rows = 3, cols = 3, and black = [[0, 0], [0, 1], [1, 0]], the output should be solution(rows, cols, black) = [1, 2, 0, 1, 0].
这道题的核心是只统计每个黑色格子会影响到的 2×2 子矩阵,而不是暴力枚举整个网格。对每个黑格子,最多只有 4 个以它为左上、右上、左下、右下角的 2×2 区域可能被影响;把这些候选子矩阵的左上角坐标放进集合去重后,再逐个数其中 4 个位置里有多少个黑格,最后累加到长度为 5 的答案数组中即可。由于黑格子数量不大,这种“只看局部、哈希去重、按黑格计数”的做法既清晰又高效。