#P4661. [BalticOI 2008] 网格 (Day2)
[BalticOI 2008] 网格 (Day2)
Description
The map of the country of Byteland is a grid of size ( is the vertical length and is the horizontal length). The labeled separating horizontal lines are called parallels and are numbered from to . The labeled separating vertical lines are called meridians and are numbered from to .
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 parallels and meridians into 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 parallels and 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 , separated by a single space.
The next lines contain the computation time for each cell. The -th number on line represents the time needed for the cell between the -th and -th parallels and between the -th and -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

The 2nd and 4th parallels and the 4th meridian divide the whole country into six rectangles, with computation times , so the total time to finish the forecast is .
Constraints
For of the testdata, .
For all testdata, , , , , .
Translated by ChatGPT 5
京公网安备 11011102002149号