#P5507. 机关

    ID: 4425 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>搜索Special JudgeO2优化广度优先搜索,BFS启发式搜索

机关

Description

There is a mechanism on the gate. It has a total of 1212 knobs, and each knob has 44 states. The states of a knob are represented by the numbers 11 to 44.

Each knob can only be rotated in one direction (states: 123411\rightarrow2\rightarrow3\rightarrow4\rightarrow1). When it is rotated, it will cause another knob to rotate once as well (in the same direction, and it will not cause a chain reaction). The same knob, when in different states, may cause different knobs to rotate (given in the input).

When all knobs are rotated to state 11, the mechanism opens.

Because the knobs have not been maintained for a long time, rotating once is difficult, and time is tight. Therefore, Steve wants to open the mechanism using the minimum number of rotations.

This task is left to you.

Input Format

There are 1212 lines, each containing 55 integers, describing the state of the mechanism.

On line ii, the first integer sis_i indicates that the initial state of the ii-th knob is sis_i.

The next 44 integers ai,j,j=1,2,3,4a_{i,j}, j=1,2,3,4 indicate that when this knob is in state jj and is rotated, it will cause the ai,ja_{i,j}-th knob to rotate to the next state.

Output Format

The first line contains an integer nn, indicating the minimum number of steps.

The second line contains nn integers, indicating the indices of the knobs rotated in order.

The testdata guarantees that a solution exists.

3 3 7 2 6
3 1 4 5 3
3 1 2 6 4
3 1 10 3 5
3 2 8 3 6
3 7 9 2 1
1 1 2 3 4
1 3 11 10 12
1 8 6 7 4
1 9 9 8 8
1 12 10 12 12
1 7 8 9 10

6
1 2 3 4 5 6

3 3 7 2 6
3 1 4 5 3
3 1 2 6 4
3 1 10 3 5
3 2 8 3 6
3 7 9 2 1
1 1 2 3 4
1 3 11 10 12
1 8 6 7 4
1 9 9 8 8
1 12 10 12 12
1 7 8 9 10

6
1 1 2 3 4 5

4 2 2 2 2
4 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1

1
1

4 9 3 4 5 
1 9 8 12 11 
4 7 5 6 12 
3 2 2 11 2 
3 6 8 2 12 
4 8 4 2 11 
2 12 9 5 3 
4 1 1 11 1 
1 1 7 4 1 
4 11 6 12 8 
2 6 3 7 6 
4 3 9 7 10 

10
11 4 6 10 7 7 5 9 9 9 

Hint

Samples 11 and 22 have the same input, and both outputs are accepted.

Explanation for sample 44:

414334 241424
Rotate knob 11 to state 3, causing knob 3 to rotate to state 1.
411334 241434
Rotate knob 4 to state 4, causing knob 11 to rotate to state 4.
411434 241444
Rotate knob 6 to state 1, causing knob 11 to rotate to state 1.
411431 241414
Rotate knob 10 to state 1, causing knob 8 to rotate to state 1.
411431 211114
Rotate knob 7 to state 3, causing knob 9 to rotate to state 2.
411431 312114
Rotate knob 7 to state 4, causing knob 5 to rotate to state 4.
411441 412114
Rotate knob 5 to state 1, causing knob 12 to rotate to state 1.
411411 412111
Rotate knob 9 to state 3, causing knob 7 to rotate to state 1.
411411 113111
Rotate knob 9 to state 4, causing knob 4 to rotate to state 1.
411111 114111
Rotate knob 9 to state 1, causing knob 1 to rotate to state 1.
111111 111111

The testdata guarantees that there is a way to open the mechanism.

Each test point is worth 1010 points.

As long as your output format is correct, you output the correct number of steps, and you provide any correct solution, you will get the score for that test point.

Otherwise, you will get 00 points for that test point.

Constraints:

Test point Required steps
1 4
2 6
3 8
4 9
5 10
6 11
7 12
8 13
9 15
10 17

Translated by ChatGPT 5