#P6158. 封锁

    ID: 6824 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>2020网络流O2优化最短路最小割凸包叉积

封锁

Background

Shocking news! zbw has actually escaped from the prison in City B!

As the police chief of City B, you must catch zbw before he escapes from your jurisdiction.

Problem Description

City B can be seen as an n×nn \times n grid. The prison is at (1,1)(1,1), and the only exit out of City B is at (n,n)(n,n). Between every two adjacent points (where Δx+Δy=1|\Delta x| + |\Delta y| = 1) there is an undirected road (there are no diagonal roads). You need to deploy guards on some roads so that no matter how zbw moves, he will have to pass through at least one of these guarded roads.

The cost to deploy guards on the road from (i,j)(i,j) to (i,j+1)(i,j+1) is ri,jr_{i,j}. The cost to deploy guards on the road from (i,j)(i,j) to (i+1,j)(i+1,j) is di,jd_{i,j}. Also, deploying guards affects people’s lives. The impact on people’s lives caused by deploying guards on the road from (i,j)(i,j) to (i,j+1)(i,j+1) is xi,jx_{i,j}, and the impact caused by deploying guards on the road from (i,j)(i,j) to (i+1,j)(i+1,j) is yi,jy_{i,j}.

Let the total cost be ww, and the total impact be ee. As an excellent police chief, you need to minimize w×ew \times e.

Input Format

The first line contains an integer nn.

Then there are n×(n1)n \times (n-1) lines. In the ii-th line, there are two integers ri/n+1,(i1)modn+1r_{i/n+1,(i-1)\bmod n+1} and xi/n+1,(i1)modn+1x_{i/n+1,(i-1)\bmod n+1}.

Then there are n×(n1)n \times (n-1) lines. In the ii-th line, there are two integers di/n+1,(i1)modn+1d_{i/n+1,(i-1)\bmod n+1} and yi/n+1,(i1)modn+1y_{i/n+1,(i-1)\bmod n+1}.

That is, the information of vertical edges is given first from top to bottom and from left to right, and then the information of horizontal edges is given from top to bottom and from left to right.

If you do not understand, please refer to the sample explanation.

Output Format

Output one integer on a single line, which is the minimum value of w×ew \times e.

3
8 3
5 2
1 1
4 2
1 2
7 5
7 2
6 1
5 4
2 3
1 4 
4 3
49

Hint

As shown in the figure, the top-left corner is (1,1)(1,1) and the bottom-right corner is (n,n)(n,n). The blue numbers represent rr, the red numbers represent xx, the yellow numbers represent dd, and the green numbers represent yy.

The optimal plan is to guard three edges:

(2,2)(2,3)(2,2)-(2,3), (3,1)(3,2)(3,1)-(3,2), (3,2)(3,3)(3,2)-(3,3).

The edge weights of the three edges are 2,32,3 --- 1,11,1 --- 4,34,3.

The answer is (1+2+4)×(1+3+3)=49(1+2+4)\times (1+3+3)=49.

You can see that there is no better solution.

This problem uses bundled testdata.

Subtasks nn Special property Score
Subtask 1 n=2n=2 None 55
Subtask 2 n400n\leq400 Random testdata 1515
Subtask 3 n10n\leq10 None
Subtask 4 n50n\leq50 3030
Subtask 5 n400n\leq400 3535

Constraints: for all testdata, 1n4001 \leq n \leq 400, $0 \leq r_{i,j}, d_{i,j}, x_{i,j}, y_{i,j} \leq 10^3$.

The testdata was strengthened on 2020/3/4, removing some solutions with incorrect time complexity.

Translated by ChatGPT 5