QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 512 MB 總分: 100

#4123. 3D View

统计

Little Yuan is a clever child who often tells his friends interesting things. Recently, he prepared to explain the cube under the illumination of colored light sources to his friends and asked you to draw it on a plane.

Little Yuan has a rectangular region of size $m \times n$, with $m \times n$ unit squares on it. Each square is stacked with some identical wooden cubes (the length, width, and height of the cubes are all 1). For convenience, we assume this region is oriented North-South. We provide an example below.

Little Yuan wants you to print the 3D view of these cubes. We define each cube as the following pattern, and it will not be rotated or turned; it is strictly presented in this form. The right side corresponds to the ASCII values of each character, where the ASCII value 32 is a space:

   +-------+
  / \     /|
 /   .*  / |
+-------+  |
|       |  |
|   *   |  |
|       | /|
|   X   |/ +
|       | /
|       |/
+-------+

In a well-lit optical environment, Little Yuan shines parallel light onto these cubes. These parallel light rays first satisfy the condition that they are all primary colors (Red, Green, Blue), and secondly, the angle of the incident light is a multiple of 45 degrees with both the $x$-axis and $y$-axis; and the angle with the $z$-axis is 45 degrees, 0 degrees, or 315 degrees. Specifically, we consider at most 9 different parallel light directions, and their incident directions can be described as:

  • Northwest 45-degree elevation, North 45-degree elevation, Northeast 45-degree elevation
  • West 45-degree elevation, Vertical incidence, East 45-degree elevation
  • Southwest 45-degree elevation, South 45-degree elevation, Southeast 45-degree elevation

For each unit cube, the three printed faces are divided into 12 small triangles, as shown in the figure below (the figure shows the regions of the 12 small triangles labeled 0, 1, 2, ..., 9, a, b).

It can be proven that the light rays hitting each small triangle are the same. If a surface is illuminated by multiple primary colors, the resulting color is the superposition of these colors. It should also be noted that the superposition of light of the same color does not produce energy accumulation; that is to say, the superposition of red light and green light is yellow; and the superposition of red light and two green lights is also yellow. These two types of yellow light are indistinguishable.

  • The three primary colors are represented by the letters $R, G, B$.
  • The three secondary colors after superposition are represented by $Y, C, P$.
  • The color after tertiary superposition, which is white, is represented by $W$.
  • Regions without any light hitting them are represented by $K$ (black).

Input

The first line contains two integers $m$ and $n$, representing that the region has $m$ rows and $n$ columns. The following $m$ lines each contain $n$ integers, representing the number of cubes stacked at the $i$-th row and $j$-th column. The following 3 lines, each containing 3 characters, describe the light colors for the 9 corresponding directions (the directions are the same as the map). Each character is one of $R, G, B$, or $*$, where $*$ means no light.

The 9 directions are in order: Northwest 45-degree elevation, North 45-degree elevation, Northeast 45-degree elevation. West 45-degree elevation, Vertical incidence, East 45-degree elevation. Southwest 45-degree elevation, South 45-degree elevation, Southeast 45-degree elevation.

Output

Output the printed effect. The output should not contain leading empty lines, and there should be no extra spaces at the end of each line. The first line of the output cannot be all spaces, and there should be no extra spaces at the end of any line.

Constraints

  • For 15% of the data, $1 \le m \le 100$ and $1 \le n \le 100$, with no light.
  • For 40% of the data, $1 \le m \le 100$ and $1 \le n \le 100$, there is only one light source, and the light direction is always Southeast.
  • For 100% of the data, $1 \le m \le 100$ and $1 \le n \le 100$, the number of cubes at each position does not exceed 100, and the light color can be any of $R$ or $B$, with at most 9 light sources.
  • Additionally, for 25% of the data, the total number of cubes does not exceed 1000, meaning the total volume of the building does not exceed 1000.

Examples

Input 1

2 2
2 1
1 1
R**
***
**G

Output 1

   +-------+
  /Y\YYYY'/|
 /YY.*'YY/G|
/.YYYY\Y/G/|
+-------+G.G|
|\GGGGG/|\:G|
|G\GGG/G|G*G|
|GG\G/GG|G:\|
|GGGXGGG|G'G+-------+
|GG/G\GG|/G/G\YYYY'/|
|G/GGG\G|G/GG.*'YY/G|
|/GGGGG\|/.GGGG\Y/G/|
+-------+-------+G.G|
/Y\GGGG'/G\GGGG'/|\:G|
/YY.*'GG/GG.*'GG/G|G*G|
/.YYYY\G/.GGGG\G/G/|G:\|
+-------+-------+G.G|G'G+
|\GGGGG/|\GGGGG/|\:G|/G/
|G\GGG/G|G\GGG/G|G*G|G/
|GG\G/GG|GG\G/GG|G:\|/
|GGGXGGG|GGGXGGG|G'G+
|GG/G\GG|GG/G\GG|/G/
|G/GGG\G|G/GGG\G|G/
|/GGGGG\|/GGGGG\|/
+-------+-------+

Input 2

3 4
1 1 2 1
1 2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

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.