#P3326. [SDOI2015] 立体图

[SDOI2015] 立体图

Description

Xiaoyuan (pinyin) is a smart kid who often explains things he finds interesting to the children around him. Recently, he plans to explain stereograms under colored horizontal light sources to the kids and asks you to help draw them on a plane.

Xiaoyuan has a rectangular area of size m×nm\times n with m×nm\times n unit squares, each of side length 11. On each square, some identical blocks are stacked (each block has length, width, and height all equal to 11).

For convenience, assume this area faces south with north at the top. Below is an example.

Xiaoyuan wants you to print the stereogram of these squares. We define each block in the following fixed format, and it will never be flipped or rotated; it is always placed strictly in this single orientation (the left side shows the pattern to be printed, and the right side shows the decimal ASCII for each position; ASCII 3232 is a space).

Under good optical conditions, Xiaoyuan shines TT beams of parallel light on these blocks simultaneously. These parallel lights satisfy: each is one of the three primary colors red, green, or blue; the angles with the xx-axis and yy-axis are multiples of 4545^\circ; and the angle with the positive zz-axis is either 4545^\circ, 00^\circ, or 315315^\circ.

Specifically, we consider at most 99 different directions of parallel light. Their incident directions can be described as: northwest with 4545^\circ elevation, due north with 4545^\circ elevation, northeast with 4545^\circ elevation, due west with 4545^\circ elevation, vertical incidence from above, due east with 4545^\circ elevation, southwest with 4545^\circ elevation, due south with 4545^\circ elevation, and southeast with 4545^\circ elevation. For each unit block, the three printable faces are divided into 1212 small triangles.

The three primary colors red, green, and blue are represented by the letters R, G, and B. The three secondary colors after double overlap, cyan, yellow, and purple, are represented by C, Y, and P, respectively. For triple overlap, i.e., white, use W.

Input Format

The first line contains two positive integers m,nm,n, meaning the area has mm rows and nn columns. Then mm lines follow, describing each row from far to near in order. Each line gives nn positive integers, indicating how many blocks are stacked at cell (i,j)(i,j).

Then there are 33 lines, each with three characters, describing the colors of light in the 99 corresponding directions (same directional order as described on the map). Each character is either one of RGB, indicating the corresponding color, or *, indicating no incident light. The nine directions, in order, are: northwest with 4545^\circ elevation, due north with 4545^\circ elevation, northeast with 4545^\circ elevation, due west with 4545^\circ elevation, vertical incidence from above, due east with 4545^\circ elevation, southwest with 4545^\circ elevation, due south with 4545^\circ elevation, and southeast with 4545^\circ elevation.

Output Format

Output the rendered result. The output must not contain a leading blank line, and there must be no extra blank line at the end. The first column must not be all spaces, and there must be no trailing spaces at the end of any line.

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

        +-------+
       /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\|/
+-------+-------+

3 4
1 1 2 1
1 2 1 2
2 1 2 1
**B
***
R*G

                            +-------+
                           /W\WWWW'/|
                          /WW.*'WW/C|
                         /.WWWW\W/C/|
                +-------+-------+-------+
               /W\WWWW'/|\YYYYY/W\WWWW'/|
              /WW.*'WW/C|G\YYY/WW.*'WW/C|
             /.WWWW\W/C/|GG\Y/.WWWW\W/C/|
    +-------+-------+-------+-------+C.C|---+
   /W\WWWW'/|\YYYYY/W\WWWW'/|\YYYYY/|\:C|C'/|
  /WW.*'WW/C|G\YYY/WW.*'WW/C|G\YYY/Y|C*C|C/C|
 /.WWWW\W/C/|GG\Y/.WWWW\W/C/|GG\Y/YY|C:\|/C/|
+-------+C.G|GGG+-------+C.G|GGGXYYY|C'C+C.C|
|\YYYYY/|\:G|GG/|\YYYYY/|\:G|GG/G\YY|/C/|\:C|
|Y\YYY/Y|C*G|G/K|Y\YYY/Y|C*G|G/GGG\Y|C/C|C*C|
|YY\Y/YY|C:\|/KK|YY\Y/YY|C:\|/GGGGG\|/C/|C:\|
|YYYXYYY|C'G+---|YYYXYYY|C'G+-------+C.C|C'C+
|YY/Y\YY|/G/G\KK|YY/Y\YY|/G/G\GGGG'/|\:C|/C/
|Y/YYY\Y|G/GG.*'|Y/YYY\Y|G/GG.*'WW/C|C*C|C/
|/YYYYY\|/.YYYY\|/YYYYY\|/.WWWW\W/C/|C:\|/
+-------+-------+-------+-------+C.C|C'C+
|\YYYYY/|\YYYYY/|\YYYYY/|\YYYYY/|\:C|/C/
|Y\YYY/Y|Y\YYY/Y|Y\YYY/Y|Y\YYY/Y|C*C|C/
|YY\Y/YY|YY\Y/YY|YY\Y/YY|YY\Y/YY|C:\|/
|YYYXYYY|YYYXYYY|YYYXYYY|YYYXYYY|C'C+
|YY/Y\YY|YY/Y\YY|YY/Y\YY|YY/Y\YY|/C/
|Y/YYY\Y|Y/YYY\Y|Y/YYY\Y|Y/YYY\Y|C/
|/YYYYY\|/YYYYY\|/YYYYY\|/YYYYY\|/
+-------+-------+-------+-------+

Hint

For 15%15\% of the testdata, 1n,m1001\leq n,m\leq 100, and there is no incident light.

For 40%40\% of the testdata, 1n,m1001\leq n,m\leq 100, there is only one incident beam, and its direction is guaranteed to be southeast.

For 100%100\% of the testdata, 1n,m1001\leq n,m\leq 100, the number of blocks stacked at each position does not exceed 100100, the incident light color may be any one of R, G, or B, and there can be at most 99 incident beams.

Translated by ChatGPT 5