Creative way of eating fish

Topic description

The cat who returned home transferred all three buckets of fish to her big rectangular pond, and then began to think: how to eat fish in the end (cats are so cute, you have to think about how to eat fish ^_ *). She found that treating large ponds as a 01 matrix (0 means no fish in the corresponding position, 1 means there are fish in the corresponding position) helps to decide the fish-eating strategy.

In the 01 matrix representing the pool, there are many square sub-matrices. If there are fishes on a diagonal line of a square sub-matrix, and there are no fish in other places of this square sub-matrix, the cat can get from this square. The "one end of the diagonal line" of the sub-matrix is ​​placed under the mouth, and the group of fresh fish on the diagonal line can be sucked into the mouth with just one suction.

Cat Mao is a greedy guy, so she wants to eat as many fish as possible in one bite. Could you please help the cat to calculate how many fish she can eat in one bite?

Input and output format

Input format:

There are multiple sets of input data, each set of data:

The first line has two integers n and m (n, m ≥ 1), which describe the size of the pond. The next n lines, each with m numbers (not "0" or "1"). Separate each two numbers with a space.

For 30% of the data, there are n,m≤100

For 60% of the data, there are n,m≤1000

For 100% of the data, there are n,m≤2500

Output format:

There is only one integer - the number of fish that the cat can eat in one bite, occupying one line, and there is a carriage return at the end of the line.

Input and output example

Input Example #1: Copy
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
Output Sample #1: Copy
3

illustrate

top right

1 0 0 0 1 0 0 0 1

Idea: At first, I thought about enumerating all submatrices violently, enumerating the length and width, and then judging whether it conforms to the meaning of the question, there are fish in a certain diagonal, but there are no fish in other places, but look at the sample point n, When m<=2500, it will collapse. If n, m is greater than 1000, it will definitely time out, so you have to change your thinking.

Code:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325240029&siteId=291194637