#P11065. 【MX-X4-T5】「Jason-1」占领高地
【MX-X4-T5】「Jason-1」占领高地
Background
Original link: https://oier.team/problems/X4F.
Problem Description
There is a map with rows and columns. The height of the cell in row , column is , and its militarization level is . It satisfies that for any two 4-directionally adjacent cells, the absolute difference of their heights is at most .
(Two cells and are 4-directionally adjacent if and only if .)
You may choose several cells to build supply stations. If a supply station is built at cell , define its transport range as all cells satisfying $h_{i,j} - h_{x,y} + p_{i,j} \geq \lvert i - x\rvert + \lvert j - y\rvert$. Each supply station can move supplies between any cells within its transport range.
Define the security level of several supply stations as the minimum value among their .
There are queries. Each query gives four integers and asks: if you want to build some supply stations to transport supplies from cell to cell , what is the maximum possible security level of the stations you build? Or report that it is impossible to complete the transport task.
Note: supplies can be transported indirectly through multiple supply stations. It is not necessary to build stations at and .
This problem guarantees .
Input Format
The first line contains three positive integers , representing the number of rows, the number of columns, and the number of queries.
The next lines each contain non-negative integers. The integer in row , column represents the height . It is guaranteed that for any two 4-directionally adjacent cells, the absolute difference of their heights is at most .
The next lines each contain non-negative integers. The integer in row , column represents the militarization level . It is guaranteed that .
The next lines each contain four positive integers , representing a query.
Output Format
Output lines. The -th line contains one integer, representing the answer to the -th query, i.e. the maximum security level that allows supplies to be transported from to . If the transport task cannot be completed no matter how many supply stations are built, output .
4 4 6
1 2 3 2
2 3 2 3
3 3 2 2
4 3 2 1
2 1 1 1
0 1 1 0
1 1 0 1
0 0 1 2
1 1 1 2
1 1 2 1
2 2 4 4
2 3 3 1
4 4 2 1
1 4 4 1
3
4
3
3
4
3
1 3 3
1 1 1
1 0 0
1 1 1 2
1 1 1 3
1 2 1 3
1
-1
-1
8 8 10
5 6 6 5 6 7 8 9
5 6 6 5 6 6 7 8
4 5 5 4 5 5 6 7
3 4 5 4 5 6 6 7
4 5 5 5 5 6 7 6
5 4 5 5 4 5 6 7
4 3 4 5 4 5 6 6
5 4 4 4 3 4 5 5
0 0 0 0 1 0 2 0
0 0 0 0 0 0 0 0
0 1 0 2 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 1 0
6 3 7 7
1 5 2 2
7 7 6 7
4 3 7 7
7 6 8 2
3 2 8 7
1 6 8 6
1 6 7 4
4 5 4 4
5 4 1 1
5
5
6
5
5
5
6
5
8
-1
Hint
[Sample Explanation #1]
For the first query, you can build a supply station at , and the security level is .
For the second query, you can build a supply station at , and the security level is .
For the third query, you can build a supply station at , and the security level is .
For the fourth query, you can build a supply station at , and the security level is .
For the fifth query, you can build a supply station at , and the security level is .
For the sixth query, you can build supply stations at and , and the security level is .
[Sample Explanation #2]
Only a supply station built at can move supplies freely between and . A supply station built at any other cell will not be able to move any supplies.
Therefore, only query can be achieved. You only need to build a supply station at , and the security level is .
[Constraints]
This problem uses bundled testdata.
| Subtask | Special Property | Score | ||
|---|---|---|---|---|
| 1 | A | |||
| 2 | B | |||
| 3 | None | |||
| 4 |
- Special property A: .
- Special property B: .
For of the testdata, , , , , , , , and it is guaranteed that for any two 4-directionally adjacent cells, the absolute difference of their heights is at most .
Translated by ChatGPT 5