题目描述
Problem Background
Translated from Nordic Olympiad in Informatics 2022 Power Grid. If you find any issues with the SPJ, please contact the problem搬运人 qvq.
$\texttt{5s, 1G}$. Please do not abuse the judging system for this problem.
Problem Description
A city is composed of $N$ rows and $M$ columns, totaling $N \times M$ squares. The power consumption of square $(i, j)$ is unknown and can be denoted as $A_{i, j}$. Since there might be power plants or no buildings at all in some squares, $A_{i, j}$ can be positive, negative, or zero.
Previously, thanks to cheap solar energy, the city had almost unlimited energy supply. However, after an accident involving millions of communication satellites colliding, only half of the sunlight reaches the Earth, forcing power plants to use more expensive energy sources. Therefore, the energy company must start charging customers for electricity, but unfortunately, no one has installed appropriate meters.
In the absence of effective methods to measure individual square's consumption, the power plant estimates the consumption of each square using the data from rows and columns. Specifically, for square $(i, j)$, we have:
$$C_{i, j} = \left| \sum _{k=1}^ N A_{k, j} - \sum _{k=1}^ M A_{i, k} \right| $$
That is, the absolute value of the difference between the total power consumption of a row and a column.
Given all $C_{i, j}$, can you construct a valid set of $A_{i, j}$?
The data guarantees that at least one solution exists.
Input Format
The first line contains two positive integers $N$ and $M$, as described in the problem statement.
The following $N$ lines, the $i$-th line contains $M$ numbers, where the $j$-th number is $C_{i, j}$, as described in the problem statement.
It is guaranteed that at least one solution exists.
Output Format
Output $N$ rows and $M$ columns, where the $i$-th row and $j$-th column contain $A_{i, j}$.
In case of multiple solutions, any valid solution is acceptable.
You need to ensure $-2^{31} \le A_{i, j} < 2^{31}$.
Sample Input and Output
Sample Input #1
2 3
3 4 1
6 7 2
Sample Output #1
1 2 6
5 3 4
Sample Input #2
3 4
0 0 0 0
0 0 0 0
0 0 0 0
Sample Output #2
0 0 0 0
0 0 0 0
0 0 0 0
Notes
Data Range
- $1 \le N, M \le 1,000$;
- $0 \le C_{i, j} \le 1,000$;
- It is guaranteed that at least one solution exists.
Subtasks
| Subtask Number | Score | Constraints |
|---|---|---|
| 1 | 8 | $N, M, C_{i, j} \le 3$ |
| 2 | 5 | $N, M, C_{i, j} \le 6$ |
| 3 | 11 | $N = 1$ |
| 4 | 6 | $N, M \ge 2$, all $C_{i, j}$ are the same |
| 5 | 15 | $N, M \ge 2$, all $C_{i, j}$ are distinct |
| 6 | 5 | $C_{i, j} \le 1$ |
| 7 | 15 | $N = M$ |
| 8 | 25 | $N, M, C_{i, j} \le 100$ |
| 9 | 10 | No additional constraints |
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分