Minecraft
Time limit1.52sMemory limit1024 MB
Given three 2D projections of a 3D 0/1 grid, construct any consistent 3D grid or report impossibility.
- Level
Medium6 of 10
- Topics
- Matrix, Greedy, Implementation
- Solved
- No attempts yet
Problem
Think of the following problem while recalling the game Minecraft, released in 2009.
There is a three-dimensional grid of size . Let be the cell on the -th layer, -th row, and -th column. Each cell contains at most one block. If the cell contains a block, ; otherwise, .
Project the grid onto the three axis-aligned planes, producing three two-dimensional grids , , and . They are defined as follows.
- If for at least one layer , then ; otherwise, .
- If for at least one row , then ; otherwise, .
- If for at least one column , then ; otherwise, .
Three grids , , and are given. Determine whether there exists a three-dimensional grid whose projections satisfy , , and .
Input
The first line contains an integer , the side length of the grid. ()
The next lines describe the grid . Each line is a length- string consisting of 0 and 1; the -th character of the -th line is .
The next lines describe the grid . Each line is a length- string consisting of 0 and 1; the -th character of the -th line is .
The final lines describe the grid . Each line is a length- string consisting of 0 and 1; the -th character of the -th line is .
Output
If a grid satisfying the conditions exists, print YES on the first line.
Then print all grids of size . Each grid must be printed using lines, and each line must be a length- string consisting of 0 and 1. In the -th printed grid, the -th character of the -th line corresponds to .
If several valid grids exist, print any one of them.
If no grid satisfies the conditions, print NO on the first line.