IOI '94 P4 - The Clocks

View as PDF

Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 8M

Problem type
IOI '94 - Haninge, Sweden
+-------+    +-------+    +-------+    
|       |    |       |    |   |   |    
|---O   |    |---O   |    |   O   |          
|       |    |       |    |       |           
+-------+    +-------+    +-------+    
    A            B            C

+-------+    +-------+    +-------+
|       |    |       |    |       |
|   O   |    |   O   |    |   O   |
|   |   |    |   |   |    |   |   |
+-------+    +-------+    +-------+
    D            E            F

+-------+    +-------+    +-------+
|       |    |       |    |       |
|   O   |    |   O---|    |   O   |
|   |   |    |       |    |   |   |
+-------+    +-------+    +-------+  (Figure 1)
    G            H            I

There are nine clocks in a 3 \times 3 array (figure 1). The goal is to return all the dials to 12 o'clock with as few moves as possible. There are nine different allowed ways to turn the dials on the clocks. Each such way is called a move. Select for each move a number 1 to 9. That number will turn the dials 90 degrees clockwise on those clocks which are affected.

Move Affected Clocks
1 ABDE
2 ABC
3 BCEF
4 ADG
5 BDEFH
6 CFI
7 DEGH
8 GHI
9 EFHI

Example

The following is one possible series of moves that transforms all the clock from Figure 1 to 12:00. However, note this is not the "correct" answer (see below).

9  9 12           9 12 12           9 12 12            12 12 12           12 12 12 
6  6  6    5->    9  9  9    8->    9  9  9    4->     12  9  9    9->    12 12 12 
6  3  6           6  6  6           9  9  9            12  9  9           12 12 12

Input Specification

The input contains three lines of three space-separated numbers; each number represents the start time of one clock, 3, 6, 9, or 12. The ordering of the numbers corresponds to the first example above.

Output Specification

A single line that contains a space separated list of the shortest sequence of moves (designated by numbers) which returns all the clocks to 12:00. If there is more than one solution, print the one which gives the lowest number when the moves are concatenated (e.g., 5 2 4 6 < 9 3 1 1).

Sample Input

9 9 12
6 6 6
6 3 6

Sample Output

4 5 8 9

Comments

There are no comments at the moment.