#P8546. 小挖的 X 献身

小挖的 X 献身

Problem Description

Given an n×nn \times n 0101 square matrix, compute the number of X’s in it.

An X is defined as a connected component filled with 11’s and shaped like an X. Specifically, an X is made up of a left-leaning diagonal \ and a right-leaning diagonal /. You must ensure that the left-leaning diagonal and the right-leaning diagonal have the same length, and the X is centrally symmetric. The diagonal length must be greater than 11.

For example:

101
010
101

There is one X with diagonal length 33.

1001
0110
0110
1001

There are two X’s with diagonal lengths 22 and 44.

10001
01010
00100
01010
00001

There is only one X with diagonal length 33.

Input Format

Line 11 contains one positive integer nn.

The next nn lines each contain a 0101 string of length nn, describing a 0101 matrix.

Output Format

Output one line containing a non-negative integer, representing the number of X’s.

5
10001
01010
00100
01011
00011
2

Hint

For 20%20\% of the testdata, 1n31 \leq n \leq 3.

For 40%40\% of the testdata, 1n101 \leq n \leq 10.

For 70%70\% of the testdata, 1n501 \leq n \leq 50.

For 100%100\% of the testdata, 1n1001 \leq n \leq 100.

Translated by ChatGPT 5