#P9803. [NERC 2018] Minegraphed
[NERC 2018] Minegraphed
Background
Translated from Problem M of NERC 2018.
Problem Description
Marika is making a game called Minegraphed. In this game, you move inside a three-dimensional rectangular cuboid. Each cell of the cuboid is either an empty cell or an obstacle cell. You are always in an empty cell, either on the bottom layer, or on top of an obstacle. For each move, you can choose one of the four directions: east, south, west, or north. The moving rules are as follows:
- You cannot move outside the cuboid.
- If the cell in front of you is empty, then you can move forward by one cell, and then fall down until you reach the bottom layer or land on an obstacle.
- If you are not on the top layer, the cell in front of you is an obstacle, and the cell above you and the cell above that obstacle are both empty, then you can climb onto the top of that obstacle.
- In all other cases, you cannot move.
There are special empty cells that you can stand on in the cuboid, numbered from to .
Marika also has a 2D array , which is the adjacency matrix of a directed graph with vertices ( means there is an edge , and vice versa). You need to make it so that vertex can reach vertex by following some directed edges if and only if, in the cuboid game field, it is possible to reach the cell numbered starting from the cell numbered by performing moves.
Please construct a valid arrangement.
Input Format
The first line contains an integer .
Then follow lines, each containing numbers , representing the adjacency matrix of the directed graph.
Output Format
Output the first line with , representing the length, width, and height of your cuboid. You must ensure that .
Then output layers (from top to bottom). Each layer is an rectangle: if is #, it means an obstacle; if it is ., it means a normal empty cell; if it is a digit, it means a special empty cell, and the digit is its corresponding index.
It is guaranteed that a solution exists.
4
0 1 0 1
0 0 1 0
0 1 0 0
1 0 0 0
4 2 3
..#.
.4..
####
1#.#
..3.
#2..
Hint
Explanation of the sample:

For all testdata, it is guaranteed that and .
Translated by ChatGPT 5