#P10644. [NordicOI 2022] 能源网格 Power Grid

[NordicOI 2022] 能源网格 Power Grid

Background

Translated from Nordic Olympiad in Informatics 2022 Power Grid。If you find that the SPJ is broken, please contact the problem porter qvq。

5s,1G\texttt{5s,1G}Please do not abuse the judging of this problem.

Problem Description

There is a city consisting of an NN by MM grid, with a total of N×MN\times M cells. The power consumption of cell (i,j)(i,j) is denoted by Ai,jA_{i,j}。Here, Ai,jA_{i,j} can be positive, negative, or 00

For cell (i,j)(i,j), define

$$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 usage of a column and the total power usage of a row。

Given all Ci,jC_{i,j}, can you construct a valid set of Ai,jA_{i,j}?

The testdata guarantees that at least one solution exists。

Input Format

The first line contains two positive integers N,MN, M, with meanings as described in the statement。

In the next NN lines, the jj-th number in line ii is Ci,jC_{i,j}, with meaning as described in the statement。

It is guaranteed that at least one solution exists。

Output Format

Output NN lines each with MM numbers, where the jj-th number in line ii is Ai,jA_{i,j}

If there are multiple solutions, output any one of them。

You need to ensure that 231Ai,j<231-2^{31}\le A_{i,j}\lt 2^{31}

2 3
3 4 1
6 7 2

1 2 6
5 3 4

3 4
0 0 0 0
0 0 0 0
0 0 0 0

0 0 0 0
0 0 0 0
0 0 0 0

Hint

Constraints

  • 1N,M10001\le N, M\le 1\, 000
  • 0Ci,j10000\le C_{i,j}\le 1\, 000
  • At least one solution is guaranteed。

Subtasks

Subtask ID Score Constraints
11 88 N,M,Ci,j3N, M, C_{i,j}\le 3
22 55 N,M,Ci,j6N, M, C_{i,j}\le 6
33 1111 N=1N=1
44 66 N,M2N, M\ge 2,all Ci,jC_{i,j} are the same
55 1515 N,M2N, M\ge 2,all Ci,jC_{i,j} are pairwise distinct
66 55 Ci,j1C_{i,j}\le 1
77 1515 N=MN=M
88 2525 N,M,Ci,j100N, M, C_{i,j}\le 100
99 1010 No additional constraints

Translated by ChatGPT 5