Marbles in a Circle
Time limit1sMemory limit256 MB
Given a ring of red, white, and green marbles with a neighbor rule, compute how many marbles of each color remain after N steps.
- Level
Hard8 of 10
- Topics
- Number theory, Math, Combinatorics, Simulation
- Solved
- No attempts yet
Problem
Colored marbles sit in a circle. Each marble is red, white, or green. Every second all marbles change color at the same time, and a marble's new color depends only on its own color and the color of the marble to its right.
The rules for changing color are:
- if the marble is white, its new color is the current color of the marble to its right.
- otherwise, if the marble to its right is white, the marble keeps its color.
- otherwise, if the marble to its right has a different color, the marble becomes white.
- otherwise the marble has the same color as the one to its right, and it flips: red becomes green, green becomes red.
You are given a string and an integer . Read as an array of characters of length , so the circle holds marbles. The character W is a white marble, R is red, and G is green. Marble is to the right of marble , and marble is to the right of marble . Determine the state of the circle after seconds.
Input
The first line contains (), the number of test cases.
Each of the next lines contains a string () and an integer () separated by a single space. consists only of the characters W, R, and G.
Output
For each test case, print one line in the form Case #X: W R G, where is the test case number starting from 1, is the number of white marbles, is the number of red marbles, and is the number of green marbles after seconds. Separate the four values with a single space.