#P8700. Plastic Sticks Puzzle Game
Plastic Sticks Puzzle Game
Plastic Sticks Puzzle Game
Little Ming is playing a puzzle game. The puzzle is made up of \(24\) plastic sticks: \(4\) yellow (denoted by Y
), \(8\) red (denoted by R
), and \(12\) green (denoted by G
). These sticks are arranged in three concentric circles:
- Outer circle: \(12\) sticks
- Middle circle: \(8\) sticks
- Inner circle: \(4\) sticks
There are three types of operations available:
-
Clockwise rotation: Rotate each circle one unit clockwise. For example, if the outer circle (starting from the 0 position and reading clockwise) is
YRYGRYGRGGGG
, after one clockwise rotation it becomesGYRYGRYGRGGG
. -
Counterclockwise rotation: Rotate each circle one unit counterclockwise. For instance, the outer circle
YRYGRYGRGGGG
becomesRYGRYGRGGGGY
after one counterclockwise rotation. -
0-point exchange: Take the stick at the 0 position from each circle and perform a cyclic swap: the outer circle's 0 stick moves to the inner circle's 0 position, the inner circle's 0 stick moves to the middle circle's 0 position, and the middle circle's 0 stick moves to the outer circle's 0 position. For example, if the three circles initially are:
- Outer:
YRYGRYGRGGGG
- Middle:
RGRGGRRY
- Inner:
GGGR
then after one exchange the circles become:
- Outer:
RRYGRYGRGGGG
- Middle:
GGRGGRRY
- Inner:
YGGR
- Outer:
The objective is to get all green sticks in the outer circle, all red sticks in the middle circle, and all yellow sticks in the inner circle. In other words, the target configuration is:
- Outer: 12 greens (
G
) - Middle: 8 reds (
R
) - Inner: 4 yellows (
Y
)
You are given an initial configuration. Determine whether it is possible to achieve the target configuration using the allowed operations. (Note that rotations let you select any stick for the exchange operation.)
inputFormat
The input consists of three lines:
- The first line is a string of length 12 representing the outer circle.
- The second line is a string of length 8 representing the middle circle.
- The third line is a string of length 4 representing the inner circle.
Each character is one of G
(green), R
(red), or Y
(yellow). It is guaranteed that the overall counts are exactly 12 green, 8 red, and 4 yellow sticks.
outputFormat
Output a single line: YES
if it is possible to achieve the target configuration, or NO
otherwise.
The target configuration is:
- Outer circle: 12
G
- Middle circle: 8
R
- Inner circle: 4
Y
sample
YRYGRYGRGGGG
RGRGGRRY
GGGR
YES