daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Mar 24th, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define ld long double
  4. #define pi pair<ll, ll>
  5. #define F first
  6. #define S second
  7. #define pb push_back
  8. #define PI acos(-1.0)
  9. using namespace std;
  10. ll n, pre[1010][4], tmp;
  11. string s;
  12. int main()
  13. {
  14.     ios::sync_with_stdio(0);
  15.     cin.tie(0); cout.tie(0);
  16.     // freopen("robots.in", "r", stdin);
  17.  
  18.     ll T;   cin >> T;
  19.     while(T--){
  20.         memset(pre, 0, sizeof pre);
  21.         int Ans = 0;
  22.  
  23.         cin >> n;
  24.         cin >> s;
  25.  
  26.         for (int i=1; i<=n; i++){
  27.             if (s[i-1] == 'P') pre[i][2] = 1;
  28.             if (s[i-1] == 'R') pre[i][1] = 1;
  29.             if (s[i-1] == 'S') pre[i][0] = 1;
  30.         }
  31.  
  32.         for (int i=1; i<=n; i++)
  33.             for (int j=0; j<3; j++)
  34.                 pre[i][j] += pre[i-1][j];
  35.  
  36.         for (int i=0; i<=n; i++)
  37.             for (int j = 0; j+i <= n; j++){
  38.                 tmp = pre[i][0] + pre[j+i][1] - pre[i][1] + pre[n][2] - pre[j+i][2];
  39.                 if (tmp > n - tmp) Ans++;
  40.             }
  41.  
  42.         cout << Ans << '\n';
  43.     }
  44.     return 0;
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top