#P7741. [AHOI2007] 石块地板

[AHOI2007] 石块地板

Problem Description

Xiao Keke arrives in the main hall of a palace. The floor of the hall is made of square stone tiles of the same size. These tiles are colored black or white, forming an m×nm \times n rectangle. Under one of the tiles there is a passage leading to the treasure vault. Xiao Keke cannot try the tiles one by one, because some tiles have traps installed: touching them will trigger the mechanism and cause the entire palace to collapse.

According to the treasure map, the passage is within a specific area. This area is a small rectangle with non-zero area, made up of several tiles, and its four sides are parallel to the edges of the hall floor. If we consider all possible rectangles in the floor, then among all rectangles, this area has the maximum value of “number of black tiles minus number of white tiles”.

Xiao Keke wants to split the work with you: he will choose the area, and you will compute the difference SS between the numbers of black and white tiles. This way, the area containing the passage can be confirmed quickly and accurately. The treasure map says that none of the tiles in this area have traps installed, so once the area is determined, the passage will definitely be found. The treasure is right ahead, so good luck.

(Assume that 11 represents a black tile, and 00 represents a white tile.)

Input Format

The first line of the input file contains two integers m,nm, n.

The next mm lines each contain nn characters. Each character is either 00 or 11.

Output Format

Output only one number, which is the maximum value of SS (as described above) among all possible areas. Output this value.

3 4
1011
1111
1111
10
4 5
10110
01111
11110
10101
8

Hint

For 50%50\% of the testdata: 1m,n2001 \le m, n \le 200.

For 100%100\% of the testdata: 1m,n4001 \le m, n \le 400.

Translated by ChatGPT 5