Dice Grid
시간 제한2초메모리 제한1024 MB
주어진 격자에서 주사위를 아래나 오른쪽으로 굴리면서 바닥 면 색이 항상 칸 색과 같도록 주사위를 칠할 수 있는지 판별하고, 가능하면 색 배치를 출력한다.
- 난이도
보통10점 중 4점
- 유형
- 구현
- 정답자
- 아직 제출이 없습니다
문제
Debora is playing a video game. In one of the levels, she is given a cube and a flat colorful grid. The cell in row and column of the grid is denoted by and has color . Debora can see the whole grid, including the color of each cell.
The cube face size matches the grid cell size. Whenever we say that the cube is located at cell , it means that its bottom face coincides with the grid cell . Opposite to the bottom face is the top face. The face that is "looking" at cell is called the front face. The back face is "looking" at cell , the right face is "looking" at cell , and the left face is "looking" at cell .
Initially, the cube is located at cell . The goal of the game is to roll the cube to cell .
From any cell , Debora can only move the cube down --- to cell , or right --- to cell . The way to move the cube down is to rotate it around the edge connecting its bottom and front faces. For instance, after the rotation, the front face becomes the new bottom face. Similarly, the way to move the cube to the right is to rotate it around the edge connecting its bottom and right faces.
The faces of the cube are not colored yet. Debora has to paint each face in any color she wants. At every moment of the game, including the moments when the cube is located at and , the cube's bottom face color has to match the color of the grid cell where the cube is located.
The goal is to paint the cube in such a way that Debora will be able to move the cube from cell to cell satisfying the conditions above. Find any possible cube coloring.
입력
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
The first line of each test case contains a single integer --- the number of rows and columns in the grid ().
The -th of the following lines contains integers (). The RGB color of cell is .
It is guaranteed that the sum of over all test cases does not exceed .
출력
For each test case, if no coloring exists, print a single word "No" on a separate line.
Otherwise, in the first line, print a single word "Yes".
In the second line, print six integers , , , , , and --- the colors of the bottom, left, back, front, right, and top faces of the cube, respectively, in its initial position at cell ().
If several possible colorings exist, print any of them.
힌트
In the third example test case, the cube can be moved from to with the following sequence of moves: right, right, right, down, down, and down.