比赛 NOIP2025模拟赛2 评测结果 AAAAAAAAAAAAAAAA
题目名称 回文块 最终得分 100
用户昵称 会挽弯弓满月 运行时间 0.192 s
代码语言 C++ 内存使用 4.04 MiB
提交时间 2025-11-25 10:05:41
显示代码纯文本
#include <bits/stdc++.h> 
typedef unsigned long long ull;
using namespace std;
const int N=5e6+10;
const ull B=131;
int _;
char s[N];
int n;
int solve(){
	ull s1=0,s2=0,b=1;
	int ans=0,t=n/2;
	for(int i=1;i<=t;i++){
		s1=s1*B+s[i];
		s2=s2+s[n-i+1]*b;
		b=b*B;
		if(s1==s2){
			ans+=2;
			s1=0;s2=0;
			b=1;
		}
	}
	if(n%2||s1) ans++;
	return ans;
}
int ans;
int main(){
	freopen("palin.in","r",stdin);
	freopen("palin.out","w",stdout);
	scanf("%d",&_);
	while(_--){
		scanf("%s",s+1);
		n=strlen(s+1);
		ans=solve();
		printf("%d\n",ans);
	}
	return 0;
}