#P5802. [SEERC 2019] Projection
[SEERC 2019] Projection
Description

You are a hardcore fan of TensorFlow, so you want to reconstruct the TensorFlow logo from two projection images.
Suppose you have a 3D space of size , and two projection images (an matrix and an matrix, with each entry being or ). You need to find a set of unit cubes such that, after placing these cubes into the 3D space, the front orthographic projection (the projection formed on the back side of the solid when light shines on the front face) and the right projection (the projection formed on the right side of the solid when light shines on the left face) are consistent with the given projection images. If there is no solution, output . If there is a solution, you need to compute two valid sets: one with the minimum number of unit cubes, and one with the maximum number. Assume gravity does not matter (i.e., unit cubes can be placed anywhere in the 3D space; they can float without support). In the matrices, means the position is covered by shadow, and means it is not covered by shadow.
If there are multiple solutions, you need to output the lexicographically smallest one. A solution is lexicographically smaller than a solution if and only if, at the first position where they differ, the number in is smaller than the corresponding number in .
For example, the solution is lexicographically smaller than .
Input Format
The first line contains three integers , representing the size of the 3D space.
In the next lines, each line contains characters or . Here, means covered by shadow, and means not covered. These characters describe the front projection.
In the next lines, each line contains characters in the same format. These characters describe the right projection.
Output Format
If there is no solution, output on the first line only.
If there is a solution, output an integer on the first line, representing the maximum number of unit cubes among all valid solutions.
In the next lines, output three integers $x, y, z \ (0 \leq x < n, 0 \leq y < m, 0 \leq z < h)$ per line, representing the positions of the unit cubes in the lexicographically smallest solution among those with the maximum number of cubes.
Then output an integer on the next line, representing the minimum number of unit cubes among all valid solutions.
In the next lines, output three integers $x, y, z \ (0 \leq x < n, 0 \leq y < m, 0 \leq z < h)$ per line, representing the positions of the unit cubes in the lexicographically smallest solution among those with the minimum number of cubes.
5 3 3
111
010
010
010
010
111
100
110
100
100
14
0 0 0
0 0 1
0 0 2
0 1 0
0 1 1
0 1 2
0 2 0
0 2 1
0 2 2
1 1 0
2 1 0
2 1 1
3 1 0
4 1 0
8
0 0 0
0 1 1
0 2 2
1 1 0
2 1 0
2 1 1
3 1 0
4 1 0
2 2 2
00
00
11
11
-1
2 3 2
101
011
10
11
6
0 0 0
0 2 0
1 1 0
1 1 1
1 2 0
1 2 1
4
0 0 0
0 2 0
1 1 0
1 2 1
Hint
A unit cube placed at will create a shadowed area at position in the front projection, and at position in the right projection.
Coordinates are numbered starting from .
Translated by ChatGPT 5
京公网安备 11011102002149号