Logo
(追記) (追記ここまで)

32831번 - Colorful Quadrants 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB4761375217.568%

문제

You are given an $n \times n$ grid, and some of the grid points are colored by one of the $k$ colors. The color of a point is represented by an integer from 0ドル$ to $k,ドル 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 $n,ドル and a point located at row $i$ and column $j$ is denoted by $(i,j)$. For an uncolored point $(i,j)$ that satisfies 1ドル < i < n$ and 1ドル < j < n,ドル we define four sub-grids by removing row $i$ and column $j$ 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 $(i,j)$. We say that $(i,j)$ 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 5ドル \times 5$ grid example. The point $(2,3)$ 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 $(4,3)$ does not have colorful quadrants because both SW and SE have color 2ドル$ only, as shown in Figure C.1(c).

Figure C.1

Given an $n \times n$ 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, $n$ and $k$ (3ドル ≤ n ≤ 2,000円,ドル 4ドル ≤ k ≤ 1,000円$), where $n$ is the number of rows and columns of the grid and $k$ is the number of colors. In the following $n$ lines, the $i$-th line contains $n$ integers that represent the colors of the points $(i,j)$ for 1ドル ≤ j ≤ n$. The integer $c$ that represents the color of a point is in range 0ドル ≤ c ≤ k$.

출력

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.

제한

예제 입력 1

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

1

예제 입력 2

3 4
1 2 3
4 1 2
3 4 1

예제 출력 2

0

예제 입력 3

4 8
0 1 2 0
8 0 0 3
7 0 0 4
0 6 5 0

예제 출력 3

0

힌트

출처

ICPC > Regionals > Asia Pacific > Korea > 2024 ICPC Asia Seoul Regional C번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /