Color Wheel (Small)
Time limit1sMemory limit256 MB
Repaint a circular string of R, G, B cells K times by a local rule, then report the final count of each color.
- Level
Medium5 of 10
- Topics
- Simulation, String, Implementation
- Solved
- No attempts yet
Problem
Jihoon prepared a color wheel for a prize event. The disc is divided into equal sectors, and each sector is painted red, green, or blue. The rule of the event is simple. Each participant picks one of red, green, and blue. Jihoon spins the wheel, and everyone whose pick matches the color of the sector the spinner lands on receives a prize.
The disc has equal sectors, so if of them are red, are green, and are blue, the probabilities of landing on each color are , , and in that order. In other words, if nobody knows which sector carries which color, all three colors are theoretically equally likely.
Jihoon surveyed the picks and found that one of the three colors was chosen far more often than the others. The reason turned out to be that somebody had looked at the wheel in advance and told a few friendly participants which color covered the most sectors. So Jihoon wants to repaint the whole wheel. The repainting works as follows. Every sector changes color at the same time.
Let be any sector of the wheel.
- If the colors of the sector left of , of itself, and of the sector right of are all the same or all different, paint blue.
- Otherwise, among the three sectors considered in step 1, two carry color and one carries color .
- If at least one of the three cases below holds, paint red. Otherwise paint green.
is red and is green, is green and is blue, is blue and is red
The sectors form a circle, so the left and right neighbors are found by stepping one sector around the disc. When , both the left and the right neighbor of are itself, and when , the two neighbors are the same sector.
Jihoon repainted the wheel once this way. Still uneasy, he repainted it more times by the same method. Find how many sectors carry each color after all repaintings.
Input
The first line contains and , separated by a space.
The second line contains a string of length that lists the color of each sector of the wheel in clockwise order. Red is given as R, green as G, and blue as B.
,
Output
Print one line with the number of red sectors, the number of green sectors, and the number of blue sectors after the repaintings, in that order, separated by spaces.