Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- //#pragma gcc optimize("Ofast,unroll-loops")
- //#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
- //#define int long long
- //#define double long double
- signed main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- int T;
- cin >> T;
- while (T--)
- {
- int N;
- string S;
- cin >> N >> S;
- int K = 1;
- while (true)
- {
- vector<vector<int>> cnt(K, vector<int>(3));
- for (int i = 0; i < N; i++)
- if (S[i] == 'R')
- cnt[i % K][0]++;
- else if (S[i] == 'P')
- cnt[i % K][1]++;
- else
- cnt[i % K][2]++;
- bool suc = false;
- string ans(K, 'R');
- for (int i = 0; i < K; i++)
- if (cnt[i][0] != cnt[i][1] || cnt[i][0] != cnt[i][2] || cnt[i][1] != cnt[i][2])
- {
- suc = true;
- if (cnt[i][0] > cnt[i][1] && cnt[i][0] > cnt[i][2])
- ans[i] = 'P';
- else if (cnt[i][1] > cnt[i][0] && cnt[i][1] > cnt[i][2])
- ans[i] = 'S';
- else if (cnt[i][2] > cnt[i][0] && cnt[i][2] > cnt[i][1])
- ans[i] = 'R';
- else if (cnt[i][0] == cnt[i][1])
- ans[i] = 'P';
- else if (cnt[i][0] == cnt[i][2])
- ans[i] = 'R';
- else
- ans[i] = 'S';
- }
- if (suc)
- {
- cout << K << '\n' << ans << '\n';
- break;
- }
- K++;
- }
- }
- return 0;
- }
- // ***** ***** * * * ***** * * ***** *****
- // * * * * * * * ** * * * *
- // * * * ***** * * * * * * *****
- // * * * * * * * * ** * *
- // **** ***** * ***** ***** * * * *
Advertisement
Add Comment
Please, Sign In to add comment