#P1736. 创意吃鱼法

    ID: 698 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp搜索递推枚举,暴力

创意吃鱼法

Description

After returning home, the cat moved all the fish from three buckets into her large rectangular pool and began to think: what method should she use to eat the fish (the cat is so cute—she even wants to figure out a tasty way to eat fish ^_*)? She finds that viewing the big pool as a 0101 matrix (00 means the corresponding cell has no fish, 11 means there is a fish) helps decide her eating strategy.

In the 0101 matrix representing the pool, there are many square submatrices. If, in some square submatrix, one of its diagonals has fish in every cell and all other cells in that submatrix have no fish, then the cat can start from one end of that diagonal and, with a single suck, pull all the fish on that diagonal into her mouth.

The cat is greedy, so she wants to eat as many fish as possible in one bite. Please help her compute the maximum number of fish she can eat in a single bite.

Input Format

The first line contains two integers nn and mm (n,m1n,m≥1), describing the size of the pool. The next nn lines each contain mm numbers (each is either 00 or 11). Adjacent numbers are separated by spaces.

Output Format

Output a single integer—the number of fish the cat can eat in one bite—on one line, followed by a newline.

4 6
0 1 0 1 0 0
0 0 1 0 1 0
1 1 0 0 0 1
0 1 1 0 1 0

3

Hint

For example, a 3×33\times 3 square submatrix with fish only along a diagonal:

1 0 0
0 1 0
0 0 1

Constraints

  • For 30%30\% of the testdata, 1n,m1001\le n,m\le 100.
  • For 60%60\% of the testdata, 1n,m10001\le n,m\le 1000.
  • For 100%100\% of the testdata, 1n,m25001\le n,m\le 2500.

Translated by ChatGPT 5