题解:AT_abc242_e [ABC242E] (∀x∀)
思路
由于规定是统计回文串的个数,那么假设
真的吗?
如果你写出来代码,会发现样例某些答案会刚好少
code
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+5;
const int mod=998244353;
int t,n,k,ans,P[N];
char a[N],b[N];
bool check(){
for(int i=1;i<=n;i++){
if(b[i]<a[i]) return true;
if(b[i]>a[i]) return false;
}
return true;
}
signed main(){
scanf("%lld",&t);
while(t--){
scanf("%lld%s",&n,a+1);
P[0]=1;
for(int i=1;i<=n;i++) P[i]=P[i-1]*26%mod;
k=(n+1)/2;
ans=0;
for(int i=1;i<=k;i++) b[i]=b[n-i+1]=a[i];
if(check()) ans++;
for(int i=1;i<=k;i++) ans=(ans+(a[i]-'A')*P[k-i]%mod)%mod;
printf("%lld\n",ans);
}
return 0;
}