6912.Corner Subgrid Count

Time Limit: 1s Memory Limit: 512MB

You are given an $n \times n$ grid whose each square is either black or white. A subgrid is called beautiful if its height and width is at least two and all of its corners are black. How many beautiful subgrids are there within the given grid?

Input Format(From the terminal/stdin)

The first input line has an integer $n$ : the size of the grid.

Then there are $n$ lines describing the grid: 1 means that a square is black and 0 means it is white.

  • $1 \le n \le 3000$

Output Format(To the terminal/stdout)

Print the number of beautiful subgrids.

Sample Input

Copy
5
00010
11111
00110
11001
00010
 \n
     \n
     \n
     \n
     \n
     \n

Sample Output

Copy
4
 \n
Source: CSES, Advanced Techniques, 2137

Submit

请先 登录

© 2025 FAQs