Repaint a circular string of R, G, B cells K times by a local rule, then report the final count of each color.
Medium5SimulationStringImplementationNo attempts yetTime limit1sMemory limit256 MBJihoon prepared a color wheel for a prize event. The disc is divided into N 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 N equal sectors, so if a of them are red, b are green, and c are blue, the probabilities of landing on each color are a/N, b/N, and c/N 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 P be any sector of the wheel.
X is red and Y is green, X is green and Y is blue, X is blue and Y is red
The sectors form a circle, so the left and right neighbors are found by stepping one sector around the disc. When N=1, both the left and the right neighbor of P are P itself, and when N=2, the two neighbors are the same sector.
Jihoon repainted the wheel once this way. Still uneasy, he repainted it K−1 more times by the same method. Find how many sectors carry each color after all K repaintings.
The first line contains N and K, separated by a space.
The second line contains a string of length N 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.
1≤N≤1000, 1≤K≤1000
Print one line with the number of red sectors, the number of green sectors, and the number of blue sectors after the K repaintings, in that order, separated by spaces.