SHARE
TWEET

Constanze's Machine CF

pawan_asipu Nov 1st, 2019 (edited) 25 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. #define mod (int)(1e9+7)
  5. #define MAXI (int)(1e15+100)
  6. #define N 100005
  7.  
  8. int power(int a,int m1)
  9. {
  10.     if(m1==0)return 1;
  11.     else if(m1==1)return a;
  12.     else if(m1==2)return (1LL*a*a)%mod;
  13.     else if(m1&1)return (1LL*a*power(power(a,m1/2),2))%mod;
  14.     else return power(power(a,m1/2),2)%mod;
  15. }
  16.  
  17.  
  18. // Driver code to tes above functions
  19. int32_t main()
  20. {
  21.    
  22.  
  23.     #ifndef ONLINE_JUDGE
  24.     // for getting input from inpu.txt
  25.     freopen("input.txt", "r", stdin);
  26.     // for writing output to output.txt
  27.     //freopen("output.txt", "w", sdtout);
  28.     #endif
  29.      
  30.     ios_base::sync_with_stdio(0);
  31.     cin.tie(NULL);
  32.     cout.tie(NULL);
  33.  
  34.     string s;
  35.     cin >> s;
  36.  
  37.     int pre[N];
  38.     pre[0] = 0;
  39.     pre[1] = 1;
  40.     for(int i=2;i<N;i++)
  41.     {
  42.         if(i%3==0)
  43.             pre[i] = ((2*pre[i-1])%mod - pre[i-2] + mod)%mod;
  44.         else if(i%3==1)
  45.             pre[i] = (pre[i-1] + pre[i-2])%mod;
  46.         else
  47.             pre[i] = ((2*pre[i-1])%mod + pre[i-2])%mod;
  48.     }
  49.  
  50.     int n = s.size(), w=0,m=0;
  51.     for(int i=0;i<n;i++)
  52.     {
  53.         if(s[i]=='w')
  54.             w++;
  55.         if(s[i]=='m')
  56.             m++;
  57.     }
  58.  
  59.     int ans = 1;
  60.     if(w!=0 or m!=0)
  61.     {
  62.         cout << 0;
  63.         return 0;
  64.     }
  65.     else
  66.     {
  67.         for(int i=0;i<n;i++)
  68.         {
  69.             if(s[i]=='n' or s[i]=='u')
  70.             {
  71.                 int c = 0, j;
  72.                 for(j=i;j<n and s[j]==s[i];j++)
  73.                     c++;
  74.                 int k = pre[c];
  75.                 ans= (ans * k)%mod;
  76.                 i = j-1;
  77.             }
  78.  
  79.         }
  80.     }
  81.  
  82.     cout << ans;
  83.  
  84.     return 0;
  85.    
  86. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top