#P9803. Minegraphed: Constructing a Fully Connected Game Board
Minegraphed: Constructing a Fully Connected Game Board
Minegraphed: Constructing a Fully Connected Game Board
Marika is developing a game called Minegraphed in which the playing field is a three-dimensional rectangular cuboid. The cuboid is divided into cells and each cell is either empty or contains an obstacle. You always stand in an "empty building," which means you are either in a cell on the bottom layer or on top of an obstacle.
You can move in one of the four cardinal directions (east, south, west, or north) with the following rules:
- You cannot move outside the bounds of the cuboid.
- If the cell directly in front of you is empty, you move one cell forward and then fall downward until you reach the bottom layer or land on an obstacle.
- If you are not on the top layer, and the cell in front of you is an obstacle, and the cell immediately above that obstacle is empty, then you can climb up to the top of the obstacle.
- In all other cases, you cannot move.
Additionally, Marika has an n × n matrix \(a\). For every pair of indices \((i, j)\), if \(a_{i,j}=1\) then building i must be able to reach building j under some sequence of moves following the rules above.
Your task is to construct any valid configuration of the game board that guarantees the required reachability. In our solution, we will use a trivial configuration that makes all buildings mutually reachable.
Note on Validity: A configuration is valid if it is possible to travel from building i to building j (by a sequence of legal moves) for every \(a_{i,j}=1\). One simple strategy is to design a board where every building is on a continuous empty path. In this problem, you will output a configuration representing a 3D cuboid.
inputFormat
The first line contains an integer n (\(1 \le n \le 1000\)), representing the number of buildings and the size of the matrix.
Each of the next n lines contains n integers (each 0 or 1) separated by spaces, representing the matrix \(a\), where \(a_{i,j}=1\) indicates that building i must be able to reach building j.
outputFormat
Output a valid configuration of the game board in the following format:
- The first line contains three integers H, R, and C representing the height, number of rows, and number of columns of the cuboid respectively.
- This is followed by H blocks. Each block consists of R lines, and each line contains C characters. The characters are:
.
denotes an empty cell.#
denotes an obstacle cell.
Your configuration must satisfy the condition that for every pair \((i,j)\) with \(a_{i,j}=1\), building i can reach building j following the movement rules.
Hint: One trivial valid solution is to produce a cuboid with H = 1
and arrange the cells in a single row containing exactly n cells, all being empty (.
). This way, if we label these cells as buildings from 1 to n, they form a continuous path, ensuring every pair is mutually reachable.
sample
1
1
1 1 1
.
</p>