P9456 [Intro Contest #14] Three-View Projection (Hard Version)

Description

> All content related to the $x, y, z$ axes/directions in this problem is based on the following $x, y, z$ axes, positions, and viewing direction. The observer stands at the position shown in the figure and is looking toward the positive direction of the $y$ axis (the green line) (the arrow direction). > ![](https://cdn.luogu.com.cn/upload/image_hosting/05erek0j.png) Now there is a cuboid region with length, width, and height (the lengths extended along the $x, y, z$ axes) of $n \text{ cm}$, $m \text{ cm}$, and $k \text{ cm}$. We divide this region into $n \times m \times k$ small cells. In each small cell, you may place a small cube with side length $1 \text{ cm}$. We use an integer triple $(x, y, z)$ to represent the position of a cell in space: it means the $x$-th cell from left to right, the $y$-th cell from front to back, and the $z$-th cell from bottom to top. ![](https://cdn.luogu.com.cn/upload/image_hosting/0yu909tc.png) For example, in the $3 \times 3 \times 3$ region shown above, according to the observer’s position, we can see that the face containing the red and blue lines (the $x, z$ axes) is the front face, the face containing the blue and green lines (the $y, z$ axes) is the left face, and the face containing the red and green lines (the $x, y$ axes) is the bottom face. The five cubes are located at $(1, 1, 1)$, $(1, 1, 2)$, $(2, 3, 2)$, $(3, 3, 2)$, $(2, 2, 3)$. A three-view drawing is obtained by observing the same 3D object from three different angles: from the top (top to bottom), from the left (left to right), and from the front (front to back). ![](https://cdn.luogu.com.cn/upload/image_hosting/p72x1i3q.png) ![](https://cdn.luogu.com.cn/upload/image_hosting/6ucamb9o.png) For example, the above are the three-view drawings of the sample region. Now, given a region and the placement of cubes in it, please help compute the three-view projections of this region.

Input Format

The input has a total of $n \times k + 1$ lines. The first line contains three integers $n, m, k$, representing the length, width, and height of the cuboid region. Next come $n \times k$ lines, each containing $m$ integers. Split them into groups of $n$ lines each. In the $x$-th group, the $y$-th line (i.e., line $(x - 1) \times n + y$), the integer in the $z$-th column is $a _ {x, y, z}$, which represents the cell at $(y, z, x)$. If $a _ {x, y, z} = 1$, it means there is a small cube in that cell; otherwise, there is no cube in that cell.

Output Format

Output a total of $2k + m$ lines. The first $k$ lines each contain $n$ integers, representing the front view **from top to bottom, from left to right**. If a position in the front view is filled, output $1$, otherwise output $0$. Separate adjacent integers in the same line by one space. The next $k$ lines each contain $m$ integers, representing the left view **from top to bottom, from back to front**. If a position in the left view is filled, output $1$, otherwise output $0$. Separate adjacent integers in the same line by one space. The next $m$ lines each contain $n$ integers, representing the top view **from back to front, from left to right**. If a position in the top view is filled, output $1$, otherwise output $0$. Separate adjacent integers in the same line by one space. **All directions above are based on the observer’s initial standing position and facing direction. If you are confused about the output order, please refer to the sample to help understand.**

Explanation/Hint

### Sample 1 Explanation Sample 1 is exactly the example shown in the statement. ![](https://cdn.luogu.com.cn/upload/image_hosting/ho4l901w.png) ### Constraints For $100\%$ of the testdata, it is guaranteed that $1 \leq n, m, k \leq 200$ and $0 \leq a _ {x, y, z} \leq 1$。 Translated by ChatGPT 5