Problem C
Cracking The Safe

This particular safe has
The safe opens when the display shows nine zeros.
For instance, if you pushed the top-left, center, center, and middle-right buttons, in this order, the safe’s display would change like so:
3 1 2 0 2 3 0 3 3 0 0 3 0 0 0 0 1 1 -> 1 1 1 -> 2 2 2 -> 3 3 3 -> 0 0 0 3 2 3 0 2 3 0 3 3 0 0 3 0 0 0
Write a program to determine if the safe can be opened, and if so, how many button pushes it would take!
Input
The input is a single test case, given as
Output
Output the number of times buttons need to be pushed to open the safe! (The same button may need to be pushed more than once, and you do not have to output which buttons must be pushed.) If the safe cannot be opened, output -1.
Sample Input 1 | Sample Output 1 |
---|---|
3 1 2 0 1 1 3 2 3 |
4 |
Sample Input 2 | Sample Output 2 |
---|---|
0 0 3 2 2 3 2 2 1 |
-1 |