joylintp

Untitled

Jun 8th, 2021
1,185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.10 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. //#pragma gcc optimize("Ofast,unroll-loops")
  5. //#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
  6. //#define int long long
  7. //#define double long double
  8.  
  9. signed main()
  10. {
  11.     ios_base::sync_with_stdio(false);
  12.     cin.tie(0);
  13.  
  14.     int T;
  15.     cin >> T;
  16.     while (T--)
  17.     {
  18.         int N;
  19.         string S;
  20.         cin >> N >> S;
  21.  
  22.         int K = 1;
  23.         while (true)
  24.         {
  25.             vector<vector<int>> cnt(K, vector<int>(3));
  26.             for (int i = 0; i < N; i++)
  27.                 if (S[i] == 'R')
  28.                     cnt[i % K][0]++;
  29.                 else if (S[i] == 'P')
  30.                     cnt[i % K][1]++;
  31.                 else
  32.                     cnt[i % K][2]++;
  33.  
  34.             bool suc = false;
  35.             string ans(K, 'R');
  36.             for (int i = 0; i < K; i++)
  37.                 if (cnt[i][0] != cnt[i][1] || cnt[i][0] != cnt[i][2] || cnt[i][1] != cnt[i][2])
  38.                 {
  39.                     suc = true;
  40.                     if (cnt[i][0] > cnt[i][1] && cnt[i][0] > cnt[i][2])
  41.                         ans[i] = 'P';
  42.                     else if (cnt[i][1] > cnt[i][0] && cnt[i][1] > cnt[i][2])
  43.                         ans[i] = 'S';
  44.                     else if (cnt[i][2] > cnt[i][0] && cnt[i][2] > cnt[i][1])
  45.                         ans[i] = 'R';
  46.                     else if (cnt[i][0] == cnt[i][1])
  47.                         ans[i] = 'P';
  48.                     else if (cnt[i][0] == cnt[i][2])
  49.                         ans[i] = 'R';
  50.                     else
  51.                         ans[i] = 'S';
  52.                 }
  53.  
  54.             if (suc)
  55.             {
  56.                 cout << K << '\n' << ans << '\n';
  57.                 break;
  58.             }
  59.             K++;
  60.         }
  61.     }
  62.  
  63.     return 0;
  64. }
  65.  
  66. //      *****  *****  *   *  *      *****  *   *  *****  *****
  67. //        *   *   *  *   *  *        *    **  *    *    *   *
  68. //       *   *   *  *****  *        *    * * *    *    *****
  69. //   *  *   *   *    *    *        *    *  **    *    *
  70. //  ****   *****    *    *****  *****  *   *    *    *
  71.  
Advertisement
Add Comment
Please, Sign In to add comment