Advertisement
leoanjos

Jumping Frog

Oct 14th, 2021
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define long long long int
  6.  
  7. int main() {
  8.     ios_base::sync_with_stdio(false);
  9.     cin.tie(NULL);
  10.  
  11.     string S; cin >> S;
  12.     int N = S.size();
  13.  
  14.     bool all_r = true;
  15.     for (int i = 0; i < N && all_r; i++)
  16.         if (S[i] != 'R') all_r = false;
  17.  
  18.     if (all_r) cout << (N - 1) << "\n";
  19.     else {
  20.         map<int, int> aux;
  21.         for (int i = 2; i < N; i++) {
  22.             int g = gcd(N, i);
  23.             if (g > 1) aux[g]++;
  24.         }
  25.  
  26.         int ans = 0;
  27.         for (auto [g, cnt]: aux) {
  28.             int size = N / g;
  29.             int jump = (N - size) / size + 1;
  30.  
  31.             bool possible = false;
  32.             vector<bool> vis(N, false);
  33.  
  34.             for (int i = 0; !vis[i] && !possible; i++) {
  35.                 possible = true;
  36.                 for (int j = i; !vis[j]; j = (j + jump) % N) {
  37.                     if (S[j] == 'P')
  38.                         possible = false;
  39.                    
  40.                     vis[j] = true;
  41.                 }
  42.             }
  43.  
  44.             if (possible) ans += cnt;
  45.         }
  46.  
  47.         cout << ans << "\n";
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement