#P7715. 「EZEC-10」Shape

「EZEC-10」Shape

Description

Person A has an n×mn \times m grid. Some cells are white, and the remaining cells are black.

Person A chooses four integers x1,x2,y1,y2x_1, x_2, y_1, y_2 satisfying the following conditions:

  1. 1x1<x2n1 \le x_1 < x_2 \le n and 1y1<y2m1 \le y_1 < y_2 \le m.
  2. x1+x2x_1 + x_2 is even.

If all cells on the following three segments are white: (x1,y1)(x2,y1)(x_1,y_1)\to(x_2,y_1), (x1,y2)(x2,y2)(x_1,y_2)\to(x_2,y_2), (x1+x22,y1)(x1+x22,y2)(\frac{x_1+x_2}{2},y_1)\to(\frac{x_1+x_2}{2},y_2), then the shape formed by these three segments is called an H-shape.

Person A wants to know how many different H-shapes exist in the grid.

Two H-shapes are the same if and only if their x1,x2,y1,y2x_1, x_2, y_1, y_2 are all the same.

Input Format

The first line contains two integers n,mn, m.

The next nn lines each contain mm integers describing the grid, where 00 means a white cell and 11 means a black cell.

Output Format

Output one integer, representing the number of different H-shapes.

3 4
1 0 0 0
1 1 0 0
1 0 0 0
1
5 3
0 1 0
0 1 0
0 0 0
0 1 0
0 1 0
2

Hint

[Sample 1 Explanation]

The H-shape with (x1,x2,y1,y2)=(1,3,3,4)(x_1,x_2,y_1,y_2)=(1,3,3,4) is valid.

[Sample 2 Explanation]

The H-shapes with (x1,x2,y1,y2)=(1,5,1,3)(x_1,x_2,y_1,y_2)=(1,5,1,3) and (2,4,1,3)(2,4,1,3) are valid.

[Constraints]

This problem uses bundled testdata.

  • Subtask 1 (1 point): n=2n=2.
  • Subtask 2 (9 points): n,m50n, m \le 50.
  • Subtask 3 (10 points): n,m100n, m \le 100, time limit is 500ms500ms.
  • Subtask 4 (30 points): n,m500n, m \le 500.
  • Subtask 5 (50 points): no special constraints.

For 100%100\% of the data, 2n,m2×1032 \le n, m \le 2 \times 10^3.

Translated by ChatGPT 5