Cube
Time limit1.5sMemory limit1024 MB
Given point recolorings in an N x N x N cube, print the first colored cube seen along each ray after rotating a chosen face to the front.
- Level
Medium5 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Statement
Imagine a cube of size made of unit cubes. Each unit cube starts colorless, so it is transparent and you can see through it. On your request, each unit cube can change color over time.
The cube stands on a glass rotating stand. It has six faces: front, back, left, right, top, and bottom. At the start, the front face faces you at eye level. Looking through the transparent cubes, you see as far as the first colored unit cube.
You get queries. The -th query has one of the following two forms:
1 X_i Y_i Z_i C_i: the unit cube in row (counting from top to bottom), column (counting from left to right), and depth (counting from front to back) changes its color to . The cube is in its initial orientation, with the front face toward you.2 S_i: rotate the cube so that face comes to the front, in front of your eyes, where the front face was before. Then print the table of colors you now see. If a position is see-through all the way, print for it. Then return the cube to its initial position, so the front face faces you again.
Input
The first line contains natural numbers and (, ).
Each of the next lines contains one query of the first or second kind.
- If the first number of a query is
1, then four more natural numbers , , , follow (, , , ). - If the first number of a query is
2, then a string follows. is one ofprednja,straznja,lijeva,desna, and it names the face to rotate to the front.
Output
For each query of the second kind, print an table, which is the answer to that query.
Hint
In the first sample, all unit cubes of the cube start colorless. The first query asks for the front face. No rotation is needed because that face already faces you. The cube is fully transparent, so the answer is a table of zeros.
The next two queries change the top-left-front corner cube to color and the bottom-right-back corner cube to color . The following two queries ask for the view after rotating the back face to the front, and after rotating the right face to the front. In the first case, the cube of color is in the top-right corner and the cube of color is in the bottom-left corner. In the second case, the view is the same as the view from the front.
In the second sample, the cube has its unit cubes in row and depth recolored. Looking from the left, you see only the cube of color . Looking from the right, you see only the cube of color .