比赛 NOIP2025模拟赛2 评测结果 AAAAAAAAAAAAAAAA
题目名称 回文块 最终得分 100
用户昵称 梦那边的没好TM 运行时间 0.144 s
代码语言 C++ 内存使用 4.20 MiB
提交时间 2025-11-25 10:28:01
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define cpy(a,b) copy(begin(a),end(a),begin(b))
#define ld long double
#define dot(x) fixed<<setprecision(x)
#define foru(a,b,c) for(ll a=b;a<=c;a++)
#define base 131

ll t;

int main(){
    freopen("palin.in" ,"r",stdin );
    freopen("palin.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cin>>t;
    while(t--){
        string s;
        cin>>s;
        ll l=0,r=s.size()-1,ans=0;
        ull hxl=0,hxr=0,bp=1;
        bool process=0;
        while(l<r){
            hxl=hxl*base+s[l];
            hxr=hxr+s[r]*bp;
            bp*=base;
            process=1;
            if(hxl==hxr){
                ans+=2,hxl=0,hxr=0,bp=1;
                process=0;
            }
            l++;
            r--;
        }
        if(l==r||process){
            ans++;
        }
        cout<<ans<<endl;
    }
    return 0;
}