#P8601. [蓝桥杯 2013 省 A] 剪格子(疑似错题)

[蓝桥杯 2013 省 A] 剪格子(疑似错题)

Description

As shown in Figure 11, some integers are filled in a 3×33\times 3 grid.

We cut along the red line in the figure and get two parts, and the sum of the numbers in each part is 6060.

Your task is to write a program to determine: for the given integers in an m×nm\times n grid, whether it can be divided into two parts such that the sums of the numbers in the two regions are equal.

If there are multiple solutions, output the minimum number of cells in the region that contains the top-left cell.

If it cannot be divided, output 00.

Input Format

The program first reads two integers mm, nn, separated by spaces (m,n<10)(m,n<10), representing the width and height of the grid.

Next are nn lines, each containing mm positive integers separated by spaces. Each integer is at most 1000010000.

Output Format

Output: among all solutions, the minimum possible number of cells in the partition region that contains the top-left cell.

3 3
10 1 52
20 30 1
1 2 3
3
4 3
1 1 1 1
1 30 80 2
1 1 1 100
10

Hint

In the second example:

Time limit: 5 seconds, 64 MB. Lanqiao Cup 2013, the 4th Provincial Contest.

Translated by ChatGPT 5