CF1380B.Universal Solution
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Recently, you found a bot to play "Rock paper scissors" with. Unfortunately, the bot uses quite a simple algorithm to play: he has a string s=s1s2…sn of length n where each letter is either R, S or P.
While initializing, the bot is choosing a starting index pos ( 1≤pos≤n ), and then it can play any number of rounds. In the first round, he chooses "Rock", "Scissors" or "Paper" based on the value of spos :
- if spos is equal to R the bot chooses "Rock";
- if spos is equal to S the bot chooses "Scissors";
- if spos is equal to P the bot chooses "Paper";
In the second round, the bot's choice is based on the value of spos+1 . In the third round — on spos+2 and so on. After sn the bot returns to s1 and continues his game.
You plan to play n rounds and you've already figured out the string s but still don't know what is the starting index pos . But since the bot's tactic is so boring, you've decided to find n choices to each round to maximize the average number of wins.
In other words, let's suggest your choices are c1c2…cn and if the bot starts from index pos then you'll win in win(pos) rounds. Find c1c2…cn such that nwin(1)+win(2)+⋯+win(n) is maximum possible.
输入格式
The first line contains a single integer t ( 1≤t≤1000 ) — the number of test cases.
Next t lines contain test cases — one per line. The first and only line of each test case contains string s=s1s2…sn ( 1≤n≤2⋅105 ; si∈{R,S,P} ) — the string of the bot.
It's guaranteed that the total length of all strings in one test doesn't exceed 2⋅105 .
输出格式
For each test case, print n choices c1c2…cn to maximize the average number of wins. Print them in the same manner as the string s .
If there are multiple optimal answers, print any of them.
输入输出样例
输入#1
3 RRRR RSP S
输出#1
PPPP RSP R
说明/提示
In the first test case, the bot (wherever it starts) will always choose "Rock", so we can always choose "Paper". So, in any case, we will win all n=4 rounds, so the average is also equal to 4 .
In the second test case:
- if bot will start from pos=1 , then (s1,c1) is draw, (s2,c2) is draw and (s3,c3) is draw, so win(1)=0 ;
- if bot will start from pos=2 , then (s2,c1) is win, (s3,c2) is win and (s1,c3) is win, so win(2)=3 ;
- if bot will start from pos=3 , then (s3,c1) is lose, (s1,c2) is lose and (s2,c3) is lose, so win(3)=0 ;
The average is equal to 30+3+0=1 and it can be proven that it's the maximum possible average. A picture from Wikipedia explaining "Rock paper scissors" game: