#P4661. [BalticOI 2008] 网格 (Day2)

[BalticOI 2008] 网格 (Day2)

Description

The map of the country of Byteland is a grid of size n×mn \times m (nn is the vertical length and mm is the horizontal length). The labeled separating horizontal lines are called parallels and are numbered from 00 to nn. The labeled separating vertical lines are called meridians and are numbered from 00 to mm.

In Byteland, weather forecasting is a very serious topic. For each cell, preparing the forecast takes some time to compute. Due to terrain conditions and other factors, different cells require different computation times. Up to now, the forecasting system processes each cell one by one, so the total time to finish forecasting is the sum of the times for all cells.

You are asked to design a new system that can run on a multi-process processor. To share the processor's computing power, Byteland will be divided by rr parallels and ss meridians into (r+1)×(s+1)(r+1) \times (s+1) rectangles. Each thread will process the cells inside one rectangle in order. Then, the computation time for a rectangle is the sum of the computation times of all cells inside that rectangle. The total time to finish the forecast is the maximum computation time among all processors.

Your task is to find the minimum possible total time after choosing rr parallels and ss meridians to split the grid.

Task

Write a program that:

  • reads from standard input the map of Byteland, the required numbers of parallels and meridians, and the processing time of each cell;
  • finds the minimum total time to finish the forecast;
  • outputs this value to standard output.

Input Format

The first line contains four positive integers n,m,r,sn, m, r, s, separated by a single space.

The next nn lines contain the computation time ci,jc_{i,j} for each cell. The jj-th number on line i+1i+1 represents the time needed for the cell between the (i1)(i-1)-th and ii-th parallels and between the (j1)(j-1)-th and jj-th meridians.

Output Format

Output one line with one integer, which is the optimal computation time.

7 8 2 1
0 0 2 6 1 1 0 0
1 4 4 4 4 4 3 0
2 4 4 4 4 4 3 0
1 4 4 4 8 4 4 0
0 3 4 4 4 4 4 3
0 1 1 3 4 4 3 0
0 0 0 1 2 1 2 0
31

Hint

Sample Explanation

0

The 2nd and 4th parallels and the 4th meridian divide the whole country into six rectangles, with computation times 21,13,27,27,17,3121, 13, 27, 27, 17, 31, so the total time to finish the forecast is 3131.

Constraints

For 40%40\% of the testdata, n10,m10n \le 10, m \le 10.

For all testdata, 1r<n181 \le r < n \le 18, 1s<m181 \le s < m \le 18, 1in1 \le i \le n, 1jm1 \le j \le m, 0ci,j2×1060 \le c_{i,j} \le 2 \times 10^6.

Translated by ChatGPT 5