题目链接
Code
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define br putchar('\n')
#define _x fixed << setprecision
#define debug(x) cout << "------" << x << "-----\n";
#define ok() cout << "Yes\n"
#define gg() cout << "No\n"
#define mem(a, b) memset(a, b, sizeof(a));
#define rep(i, a, b) for (int i = a;i <= b; ++i)
#define rrep(i, a, b) for(int i = a; i >= b; --i)
#define All(a) ((a.begin()), (a.end()))
#define IOS ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int mod = 998244353;
LL gcd(LL a, LL b) { return b ? gcd(b, a%b) : a; }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
LL qmul(LL a, LL b, LL p) {
a %= p; b %= p;
LL ret = 0;
LL tmp = a;
while(b) {
if( b & 1) {ret += tmp; if(ret > p ) ret -= p;}
tmp <<= 1; if(tmp > p) tmp -= p;
b >>= 1;
}
return ret;
}
LL qpow(LL a, LL b, LL p){
LL Ans = 1;
LL ret = a % p;
while(b) {
if(b & 1) Ans = qmul(Ans, ret, p);
ret = qmul(ret, ret, p);
b >>= 1;
}
return Ans;
}
signed main(){
#ifdef ONLINE_JUDGE
#else
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif
IOS;
int tt; cin >> tt;
while (tt -- )
{
int ans = 0;
string t = "nunhehheh", s;
cin >> s;
s = '0' + s;
int len = s.size();
vector<int> a(len+10, 0);
for(int i = len; i; -- i) a[i] = a[i + 1] + (s[i] == 'a');
vector<vector<int> > dp(len + 10, vector<int>(11, 0));
for(int i = 1; i <= len; ++i)
{
dp[i][1] = (dp[i - 1][1] + (s[i] == 'n')) % mod;
dp[i][2] = (dp[i - 1][2] + dp[i - 1][1] * (s[i] == 'u')) % mod;
dp[i][3] = (dp[i - 1][3] + dp[i - 1][2] * (s[i] == 'n')) % mod;
dp[i][4] = (dp[i - 1][4] + dp[i - 1][3] * (s[i] == 'h')) % mod;
dp[i][5] = (dp[i - 1][5] + dp[i - 1][4] * (s[i] == 'e')) % mod;
dp[i][6] = (dp[i - 1][6] + dp[i - 1][5] * (s[i] == 'h')) % mod;
dp[i][7] = (dp[i - 1][7] + dp[i - 1][6] * (s[i] == 'h')) % mod;
dp[i][8] = (dp[i - 1][8] + dp[i - 1][7] * (s[i] == 'e')) % mod;
dp[i][9] = (dp[i - 1][8] * (s[i] == 'h')) % mod;
if(dp[i][9]) ans = (ans + (qpow(2, a[i + 1], mod) - 1) * dp[i][9]) % mod;
}
cout << ans << endl;
}
return 0;
}