#P14767. [ICPC 2024 Seoul R] Colorful Quadrants
[ICPC 2024 Seoul R] Colorful Quadrants
题目描述
You are given an grid, and some of the grid points are colored by one of the colors. The color of a point is represented by an integer from 0 to , where 0 represents the uncolored case. Note that multiple points may be colored the same. The rows and columns of the grid are denoted by integers from 1 to , and a point located at row and column is denoted by . For an uncolored point that satisfies and , we define four sub-grids by removing row and column from the grid. Each of the four sub-grids is called NW (northwest), NE (northeast), SW (southwest), and SE (southeast) based on the position relative to . We say that has colorful quadrants if, when selecting one point from each of the four sub-grids, the chosen four points are all of different colors.
See Figure C.1(a) as a grid example. The point has colorful quadrants because NW has color 1, NE has color 4, SW has color 3, and SE has color 2, as shown in Figure C.1(b). However, the point does not have colorful quadrants because both SW and SE have color 2 only, as shown in Figure C.1(c).
:::align{center}

Figure C.1 :::
Given an grid containing at least four grid points colored in different colors, write a program to count the number of uncolored points that have colorful quadrants.
输入格式
Your program is to read from standard input. The input starts with a line containing two integers, and (, ), where is the number of rows and columns of the grid and is the number of colors. In the following lines, the -th line contains integers that represent the colors of the points for . The integer that represents the color of a point is in range .
输出格式
Your program is to write to standard output. Print exactly one line. The line should contain the number of uncolored points that have colorful quadrants.
5 4
0 1 0 0 4
2 0 0 1 3
3 0 2 0 0
0 0 0 0 0
0 2 1 2 0
1
3 4
1 2 3
4 1 2
3 4 1
0
4 8
0 1 2 0
8 0 0 3
7 0 0 4
0 6 5 0
0