CF1762C 题解
思路
我们手搓一个数据:
第一个前缀:
第二个前缀:
第三个前缀:
第四个前缀:
第五个前缀:
第六个前缀:
然后我们发现,如果出现
代码
# include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int mod = 998244353;
int t, n, sum, now;
string a;
int main () {
ios::sync_with_stdio (0);
cin.tie (0);
cout.tie (0);
cin >> t;
while (t --) {
cin >> n >> a;
sum = now = 1;
for (int i = 1; i < n; ++ i) {
if (a[i] != a[i - 1])
now = 1;
else
now <<= 1, now %= mod;
sum += now, sum %= mod;
}
cout << sum << '\n';
}
return 0;
}