Under construction

Still being built. Things may change

Advanced ASCII Cubes

Time limit1sMemory limit128 MB

Summary
Render stacked cubes on an N by M grid as ASCII art using isometric projection, minimizing output lines and width.
Level

Medium4 of 10

Topics
Implementation, Simulation, Matrix
Solved
No attempts yet

Problem

The table surface is divided into an N×MN \times M grid of square cells. Over some cells, cubes are stacked one on top of another to form towers. For each cell, the number of cubes stacked over it is given by the matrix AA.

Your program must render the view of the table in ASCII graphics, where each cube is drawn as shown below:

  +---+
 /   /|
+---+ |
|   | +
|   |/
+---+

(the characters used are +, -, /, |, whose ASCII codes are 43, 45, 47, 124). Use the dot . (ASCII 46) as the background.

Input

The input contains the integers NN and MM, followed by the matrix AA given row by row. The first row describes the towers of cubes farthest from the viewer, from left to right; the last row describes the towers nearest to the viewer.

Output

Output the ASCII view of the table using the minimal number of lines needed to show all cubes. Every line must have the same length, equal to the minimal width needed to show all cubes.

Constraints

  • 1≤N,M,Aij≤401 \le N, M, A_{ij} \le 40

Examples2

  1. Example 1

    Input
    3 4
    1 1 1 1
    1 2 1 1
    1 1 1 1
    
    Expected output
    ........+---+..........
    ......+/   /|-+---+---+
    ...../+---+ |/   /   /|
    ....+-|   | +---+---+ |
    .../  |   |/   /   /| +
    ..+---+---+---+---+ |/.
    ./   /   /   /   /| +..
    +---+---+---+---+ |/...
    |   |   |   |   | +....
    |   |   |   |   |/.....
    +---+---+---+---+......
    
  2. Example 2

    Input
    3 5
    2 2 1 2 2
    2 2 1 1 2
    3 2 1 2 2
    
    Expected output
    ......+---+---+...+---+---+
    ..+---+  /   /|../   /   /|
    ./   /|-+---+ |.+---+---+ |
    +---+ |/   /| +-|  /   /| +
    |   | +---+ |/+---+---+ |/|
    |   |/   /| +/   /   /| + |
    +---+---+ |/+---+---+ |/| +
    |   |   | +-|   |   | + |/.
    |   |   |/  |   |   |/| +..
    +---+---+---+---+---+ |/...
    |   |   |   |   |   | +....
    |   |   |   |   |   |/.....
    +---+---+---+---+---+......