AtCoder Grand Contest 064
E
Cross Sum Construction
AtCoder
⌀ 4069
原题
← DF →
翻译中…

Problem Statement

翻译中…

You are given a positive integer $N$ and integer sequences of length $N$: $A=(a_1,\ldots,a_N)$ and $B=(b_1,\ldots,b_N)$. Let $X$ be the multiset of $N^2$ instances $(a_i+b_j)(1 \leq i,j \leq N)$.

翻译中…

For an $N \times N$ matrix $M$ whose elements are integers between $-10^{18}$ and $10^{18}$, inclusive, we define the score as follows.

翻译中…
  • Let $S$ be the multiset of $N^2$ instances, each of which is the sum of the $2N-1$ elements in the $i$-th row or $j$-th column of $M$ $(1 \leq i,j \leq N)$. Then, the score is the sum of $\min($the multiplicity of $z$ in $X$, the multiplicity of $z$ in $S)$ over all integers $z$.
翻译中…

Find a matrix $M$ with the maximum score.

翻译中…

Solve the above problem for $T$ cases.

翻译中…

Constraints

翻译中…
  • $1 \leq T \leq 2.5 \times 10^5$
  • $1 \leq N \leq 500$
  • $-10^9 \leq a_i,b_i \leq 10^9$
  • The sum of $N^2$ over the test cases in a single input is at most $2.5 \times 10^5$.
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format, where $\mathrm{test}_i$ represents the $i$-th test case:

翻译中…

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

翻译中…

Each test case is given in the following format:

翻译中…

N
a_1 \ldots a_N
b_1 \ldots b_N

翻译中…

Output

翻译中…

For each test case, print a solution in the following format:

翻译中…

m_{1,1} \ldots m_{1,N}
\vdots
m_{N,1} \ldots m_{N,N}

翻译中…

Here, $m_{i,j}$ is the element at the $i$-th row and $j$-th column of a matrix $M$ with the maximum score, and must be an integer such that $-10^{18} \leq m_{i,j} \leq 10^{18}$. If multiple matrices $M$ have the maximum score, any one of them is accepted.

翻译中…

样例

Input #1
3
1
5
-10
2
0 -1
8 -11
3
20 23 26
1 2 3
Output #1
-5
8 9
-10 -9
2 9 4
7 5 3
6 1 8
For the input and output in the first case, $X=\{-5\}, S=\{-5\}$, for a score of $1$. For the input and output in the second case, $X=\{8,-11,7,-12\}, S=\{7,8,-11,-10\}$, for a score of $3$. For the input and output in the third case, $X=\{21,22,23,24,25,26,27,28,29\}, S=\{28,21,26,23,25,27,24,29,22\}$, for a score of $9$.
题目信息
题号
agc064_e
时间限制
3 s
内存限制
1024 MB

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