Spinner (Large)
Time limit1sMemory limit256 MB
Given a circular row of R, G, B cells and a three-cell local update rule, count each color after K synchronous rounds with K up to 1e9.
- Level
Medium7 of 10
- Topics
- Simulation, Math
- Solved
- No attempts yet
Problem
Jihun prepared a spinner for a prize event. The circular board is divided into equal parts, and each part is painted red, green, or blue. A participant picks one of the three colors. The board is spun, and everyone whose color matches the color of the part the spinner stops on receives a prize. If of the parts are red, are green and are blue, then the chance of each color is , and . So if nobody knows which part carries which color, all three colors are equally likely.
Jihun checked which colors the participants had picked and found that one of the three colors was picked far more often. The reason was that someone had looked at the spinner and told a few acquainted participants which color covered the most parts. Jihun therefore wants to repaint the whole board.
Number the parts 1 to clockwise. The left part of part is part and the right part is part , where the left part of part 1 is part and the right part of part is part 1.
One round of repainting works as follows. Every part changes color at the same time, and for each part you look at the three colors painted on the left part of , on itself, and on the right part of .
- If the three colors are all the same or all different, repaint blue.
- Otherwise two of the three parts carry color and the remaining one carries a different color .
- If is (red, green), (green, blue) or (blue, red), repaint red. Otherwise repaint it green.
Jihun repeated this round times in total. Find how many parts carry each color after the rounds.
Input
The first line contains and , separated by a space.
The second line contains a string of length that lists the color painted on every part, starting at part 1 and going clockwise. Red is given as R, green as G and blue as B.
,
Output
Print one line holding the number of red parts, the number of green parts and the number of blue parts after all rounds, in that order, separated by single spaces.