COFO::1245C Constanze’s Machine

Problem

Point

Design

Complexity

Code

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define r_rep(i, a, b) for(int i=(a); i >(b); i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

string s;
ull dp[100005];
ull MOD = 1e9 + 7;
void get_series(char what, vector<ull>& v){
    bool f = false;
    int cnt = 0;
    rep(i, 0, s.size()){
        if(s[i] == what){
            f = true;
            cnt++;
        }
        else{
            if(cnt > 1) v.push_back(cnt);
            cnt = 0;
            f = false;
        }
    }
    if(cnt > 1) v.push_back(cnt);
}
ull fibonacci(ull i){
    if(i < 0) return 0;
    if(dp[i]) return dp[i];
    return dp[i] = (fibonacci(i-1) % MOD + fibonacci(i-2) % MOD) % MOD;
}
void solve(){
    cin >> s;
    ull ans = 1;
    vector<ull> v;
    
    // exception
    bool f = false;
    rep(i, 0, s.size()) if(s[i] == 'm' || s[i] == 'w'){
        f = true;
        break;
    }
    if(f){
        cout << "0" << '\n';
        return;
    }
    
    // fibonacci
    dp[0] = 0, dp[1] = 1, dp[2] = 2;
    get_series('u', v);
    get_series('n', v);
    
    rep(i, 0, v.size()) ans = (ans * fibonacci(v[i])) % MOD;
    
    if(v.size() == 0) cout << 1 << '\n';
    else cout << ans << '\n';
}
int main(){
    solve();
    return 0;
}