提交时间:2025-06-08 14:42:02

运行 ID: 37980

#include <bits/stdc++.h> #define int long long using namespace std; const int mod = 998244353; string s; int n,m; int a[202]; int b[202]; int a1,a2,a3; signed main () { cin >> s; n = s.size(); for (int i = 0;i < n;i++) { if (s[i] == '?') { m++; a[i] = m; } } for (int i = 0;i < (1ll << m);i++) { string st = s; for (int j = 0;j < n;j++) { if (st[j] == '?') { if ((1ll << (a[j] - 1)) & i) { st[j] = 'a'; } else { st[j] = 'b'; } } } st = st + st; st = st + st; int j = 1; int xl,xr; while (j < st.size()) { if (st[j - 1] != st[j]) { j++; } if (b[j % n]) { xl = b[j % n] + 1; xr = j; break; } b[j % n] = j; j += 2; } j = xl + 1; // cout << st << ' ' << xl << ' ' << xr << endl; int A = 0,B = 0; while (j <= xr) { if (st[j - 1] != st[j]) { j++; } if (st[j] == 'a') { A++; } else { B++; } j += 2; } // cout << A << ' ' << B << endl; if (A - B < 0) { a1++; } else if (A - B > 0) { a2++; } else { a3++; } memset(b,0,sizeof(b)); } cout << a2 % mod << endl; cout << a3 % mod << endl; cout << a1 % mod << endl; return 0; }