#P3400. 仓鼠窝

仓鼠窝

Description

The adorable "Created equal" is a little hamster, and of course a little hamster has a hamster nest.

The nest is an n×mn\times m matrix with nn rows and mm columns. The little hamster wants to know how many submatrices this matrix has.

For example, for a 2×32\times 3 matrix, there are 66 submatrices of size 1×11\times 1, 44 of size 1×21\times 2, 22 of size 1×31\times 3, 33 of size 2×12\times 1, 22 of size 2×22\times 2, and 11 of size 2×32\times 3, so in total there are 6+4+2+3+2+1=186+4+2+3+2+1=18 submatrices.

However, some cells in the nest are damaged. Now the little hamster wants to know how many submatrices contain no damaged cells.

Input Format

The first line contains two positive integers nn and mm, denoting the number of rows nn and columns mm of the nest.

Then follow nn lines, each containing mm numbers. Each number is either 00 or 11. A 00 means the cell is damaged; otherwise the cell is intact.

Output Format

Output a single integer: the number of submatrices that are undamaged.

3 4
1 1 1 1
1 0 1 1
1 1 0 1
26

Hint

The time limit is 2s2\text{s} and the memory limit is 256M256\text{M}. Since the new judge is close in speed to the NOIP judge, please be mindful of the impact of constant factors.

Testdata index nn mm Special property
1, 2, 3 2 None
4 10
5, 6 2000 All cells undamaged
7 2500 3000 Exactly one cell broken
8 3000 2500
9 200 None
10, 11, 12 500
13, 14 1000 1000
15 1500
16 2500 2500
17 3000
18 3000 2500
19, 20 3000

Translated by ChatGPT 5