Time Limit: Java: 2000 ms / Others: 2000 ms
Memory Limit: Java: 65536 KB / Others: 65536 KB
This puzzle consists of a random sequence of m black disks and n white disks on an oval-shaped track, with a turnstile capable of flipping (i.e., reversing) three consecutive disks. In Figure 1, there are 8 black disks and 10 white disks on the track. You may spin the turnstile to flip the three disks in it or shift one position clockwise for each of the disks on the track (Figure 1).
Figure 1. A flip and a shift
The goal of this puzzle is to gather the disks of the same color in adjacent positions using flips and shifts. (Figure 2)
Figure 2. A goal sequence
You are to write a program which decides whether a given sequence can reach a goal or not. If a goal is reachable, then write a message ��YES��; otherwise, write a message ��NO��.