#P7239. 3D Cube
3D Cube
Description
Little Z got a 2D matrix. The base can be viewed as an grid.
On each cell, you may stack any number of cubes. Due to gravity, cubes will not float in the air, and they are not glued together.
He provides the three orthographic views of this 3D matrix. Please construct a cube arrangement that satisfies the following condition:
For each row and each column, there is at most one "peak". In particular, the heights around the border of the base matrix are considered to be . For example, 12321 has one "peak", while 13231 has two "peaks".
More examples:
| Cube arrangement | Number of "peaks" |
|---|---|
Find the matrix that uses the minimum number of cubes. If there is no solution, output -1.
Input Format
The first line contains two integers: .
The second line contains integers: the left view. The -th integer represents the number of cubes in the -th column of the left view.
The third line contains integers: the front view. The -th integer represents the number of cubes in the -th column of the front view.
The next lines each contain integers: the top view, where 0 means there is no cube, and 1 means there is at least one cube.
Output Format
If there is no solution, output -1.
Otherwise output lines, each containing non-negative integers, representing the constructed top view of the 3D matrix. The integer in row and column denotes the number of cubes at that position.
Make sure to output exactly in the required format, otherwise the SPJ may return results such as UKE.
3 3
2 2 2
2 2 2
0 1 0
1 1 1
0 1 0
0 2 0
2 2 2
0 2 0
Hint
Constraints
All subtasks in this problem use bundled tests.
For of the testdata: the input files are given, and your program should output the answers by table lookup; see the attachment easy.zip.
For of the testdata: . In the top view, each cell has at most cubes, and the number of 1 in the top view is .
Translated by ChatGPT 5
京公网安备 11011102002149号