#P3400. 仓鼠窝
仓鼠窝
Description
The adorable "Created equal" is a little hamster, and of course a little hamster has a hamster nest.
The nest is an matrix with rows and columns. The little hamster wants to know how many submatrices this matrix has.
For example, for a matrix, there are submatrices of size , of size , of size , of size , of size , and of size , so in total there are 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 and , denoting the number of rows and columns of the nest.
Then follow lines, each containing numbers. Each number is either or . A 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 and the memory limit is . Since the new judge is close in speed to the NOIP judge, please be mindful of the impact of constant factors.
| Testdata index | 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
京公网安备 11011102002149号