P1058 [NOIP 2008 Junior] 3D Diagram
Description
Xiao Yuan is a smart kid who often tells his friends things he finds interesting. Recently, he plans to explain 3D diagrams to them and asks you to draw the 3D diagram.
Xiao Yuan has a rectangular area of size $m \times n$ consisting of $m \times n$ unit squares. On each square, some identical blocks are stacked (each block has length, width, and height all equal to $1$). He wants you to print the 3D diagram of these squares. Each block is defined in the following format, and there is no flipping or rotation; blocks are placed strictly in this single orientation:
$$
\def\arraystretch{1e-10}
\begin{aligned}
&\verb! +---+!\\
&\verb! / /|!\\
&\verb!+---+ |!\quad\textsf{高}\\
&\verb!| | +!\\
&\verb!| |/ !\quad\textsf{宽}\\
&\verb!+---+ !\\
& \quad\textsf{长}
\end{aligned}$$
Each vertex is represented by one plus sign `+`, the length by three `-`, the width by one `/`, and the height by two `|`. The ASCII codes of characters `+`, `-`, `/`, `|` are $43$, $45$, $47$, $124$, respectively. The character `.` (ASCII code $46$) must be printed as the background; that is, blank areas in the 3D diagram should be filled with `.`. The drawing rules are as follows:
If two blocks are adjacent horizontally (left-right), they look like:
$$
\def\arraystretch{1e-10}
\begin{aligned}
\verb!..+---+---+!\\
\verb!./ / /|!\\
\verb!+---+---+ |!\\
\verb!| | | +!\\
\verb!| | |/.!\\
\verb!+---+---+..!\\
\end{aligned}
$$
If two blocks are adjacent vertically (up-down), they look like:
$$
\def\arraystretch{1e-10}
\begin{aligned}
\verb!..+---+!\\
\verb!./ /|!\\
\verb!+---+ |!\\
\verb!| | +!\\
\verb!| |/|!\\
\verb!+---+ |!\\
\verb!| | +!\\
\verb!| |/.!\\
\verb!+---+..!\\
\end{aligned}
$$
If two blocks are adjacent front-to-back, they look like:
$$
\def\arraystretch{1e-10}
\begin{aligned}
\verb!....+---+!\\
\verb!.../ /|!\\
\verb!..+---+ |!\\
\verb!./ /| +!\\
\verb!+---+ |/.!\\
\verb!| | +..!\\
\verb!| |/...!\\
\verb!+---+....!\\
\end{aligned}
$$
In the 3D diagram, define the lower-left corner vertex of the bottom-most block on the square at $(m, 1)$ (i.e., row $m$, column $1$) as the lower-left corner of the entire diagram.
Input Format
The first line contains two integers $m$ and $n$ separated by a space, indicating there are $m \times n$ squares ($1 \le m, n \le 50$).
The next $m$ lines give an $m \times n$ matrix. Each line contains $n$ integers separated by spaces; the integer at row $i$, column $j$ is the number of blocks stacked on that square ($1 \le$ the number of blocks on each cell $\le 100$).
Output Format
Output the required 3D diagram as a $K$-row by $L$-column character matrix, where $K$ and $L$ are the minimal numbers of rows and columns needed to print the diagram according to the rules.
Explanation/Hint
NOIP 2008 Junior, Problem 4.
Translated by ChatGPT 5