| 比赛 |
NOIP2025模拟赛2 |
评测结果 |
AAAAAAAAAAAAAAAA |
| 题目名称 |
回文块 |
最终得分 |
100 |
| 用户昵称 |
梦那边的美好TE |
运行时间 |
0.795 s |
| 代码语言 |
C++ |
内存使用 |
43.91 MiB |
| 提交时间 |
2025-11-25 08:18:35 |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef unsigned long long ull;
const int N=5e6+10;
const int P=131;
ull hs[N],pw[N];
char s[N];
int T,n,ans;
ull ask(int l,int r){
return hs[r]-hs[l-1]*pw[r-l+1];
}
void work(){
scanf("%s",s+1);
int n=strlen(s+1);
for(int i=1;i<=n;i++)hs[i]=hs[i-1]*P+s[i];
int l=1,r=n,i=1,j=n;
while(i<j){
if(ask(l,i)==ask(j,r)){
ans+=2;
l=i+1,r=j-1;
}
i++,j--;
}
if(l<=r)ans++;
printf("%d\n",ans);
return;
}
void clear(){
ans=0;
}
int main(){
freopen("palin.in","r",stdin);
freopen("palin.out","w",stdout);
pw[0]=1;
for(int i=1;i<=5e6;i++)pw[i]=pw[i-1]*P;
scanf("%d",&T);while(T--)work(),clear();
return 0;
}