AtCoder Regular Contest 206 (Div. 2)
E
Rectangle Coloring
AtCoder
⌀ 2902
原题
← D→
翻译中…

Problem Statement

翻译中…

There is an $N\times N$ board, where $N$ is at least $4$. The cells on the outermost edge of the board that are not corners are called good cells. More formally, among $(i,j)$ such that $1\leq i,j \leq N$ and $i=1$ or $i=N$ or $j=1$ or $j=N$, the cells excluding $(1,1),(1,N),(N,1),(N,N)$ are called good cells. Here, $(r,c)$ refers to the cell in row $r$ and column $c$.

翻译中…

All good cells have integers written on them. This information is given as four integer sequences of length $N-2$: $U=(U_1,\ldots,U_{N-2}),D=(D_1,\ldots,D_{N-2}),L=(L_1,\ldots,L_{N-2}),R=(R_1,\ldots,R_{N-2})$.

翻译中…

Each element of these integer sequences corresponds to the integer written on a good cell as follows:

翻译中…
  • $U_i$: $(1,i+1)$
  • $D_i$: $(N,i+1)$
  • $L_i$: $(i+1,1)$
  • $R_i$: $(i+1,N)$
翻译中…

Also, all cells on the board are initially colored white. You can perform the following operation any number of times:

翻译中…
  • Choose two good cells that have never been chosen in any previous operation. Let the two chosen good cells be $(r_1,c_1)$ and $(r_2,c_2)$. For all $(i,j)$ satisfying $\min(r_1,r_2)\leq i \leq \max(r_1,r_2)$ and $\min(c_1,c_2)\leq j \leq \max(c_1,c_2)$, color $(i,j)$ black. The cost of the operation is the sum of the integers written on the two chosen good cells.
翻译中…

Find the minimum total cost required to color all cells black.

翻译中…

Answer for $T$ test cases.

翻译中…

Constraints

翻译中…
  • All input values are integers.
  • $1 \leq T \leq 12500$
  • $4 \leq N \leq 5\times 10^4$
  • $0\leq U_i,D_i,L_i,R_i \leq 10^9$
  • The sum of $N$ over all test cases does not exceed $5\times 10^4$.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

T
\mathrm{case}_1
\vdots
\mathrm{case}_T

翻译中…

Each test case is given in the following format:

翻译中…

N
U_1 \ldots U_{N-2}
D_1 \ldots D_{N-2}
L_1 \ldots L_{N-2}
R_1 \ldots R_{N-2}

翻译中…

Output

翻译中…

Output $T$ lines.

翻译中…

For the $i$-th line, output the answer for the $i$-th test case.

翻译中…

样例

Input #1
3
4
1 2
5 6
7 8
3 4
6
6 2 10 2
7 1 3 0
2 4 4 2
2 10 6 4
8
5 0 6 10 1 8
5 5 9 9 4 7
7 3 4 9 7 6
10 9 0 4 10 5
Output #1
36
15
21
In the $1$-st test case, you can color all cells black as follows: - Perform the operation choosing $(1,2)$ and $(3,4)$. - Perform the operation choosing $(2,4)$ and $(4,2)$. - Perform the operation choosing $(4,3)$ and $(2,1)$. - Perform the operation choosing $(3,1)$ and $(1,3)$. The total cost is $(1+4)+(3+5)+(6+7)+(8+2)=36$. ![image](https://img.atcoder.jp/arc206/70f2b55f8ba2310c24707b33dd4589f1.png) For the $2$-nd and $3$-rd test cases, the input boards are illustrated below: ![image](https://img.atcoder.jp/arc206/9b0d44ca21342b6e386fc4492ebe61fd.png)
题目信息
题号
arc206_e
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。