ABC242E解题报告
Empty_Dream · · 题解
题意
有
分析
参考 C题 的思路,还是类似递推的做法。
对于两个字符串
根据这个性质,定义 A 的值(即可以取多少个小于
最后加上
在每一次询问时一定不要清空
代码
#include <bits/stdc++.h>
#define int long long
using namespace std;
int mod = 998244353;
int t, n;
int dp[1000005];
string s;
bool check(){//判断原串是否能是回文
string t = " ";
for (int i = 1; i <= (n + 1) / 2; i++) t += s[i];
for (int i = n - (n + 1) / 2; i >= 1; i--) t += s[i];
return t <= s;
}
signed main(){
cin >> t;
while (t--){
cin >> n >> s;
s = ' ' + s;
for (int i = 1; i <= (n + 1) / 2; i++) dp[i] = (dp[i - 1] * 26 + s[i] - 'A') % mod;//递推
cout << (dp[(n + 1) / 2] + check()) % mod << endl;
}
return 0;
}