#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
using namespace std;
const ll p=1e9+7;
const ll c=31;
ll hah[1000010];
ll inv(ll a){
return (p-p/a)*int(p%a)%p;
}
ll pw(ll a,ll b){
ll ans=1;
while(b){
if(b&1)ans*=a,ans%=p;
b>>=1;
a*=a;
a%=a;
}
return ans;
}
ll hh(int l,int r){
return ((hah[r]-hah[l-1]*pw(c,r-l+1))%p+p)%p;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
while(t--){
string s;
cin>>s;
int n=s.size();
for(int i=1;i<=n;i++){
char ch=s[i-1];
ll val=int(ch-'a')+1;
hah[i]=hah[i-1]*c+val;
hah[i]%=p;
}
int l=1,r=n,i=0,ans=0;
while(l<=r){
while(l+i!=r&&hh(l,l+i)!=hh(r-i,r)){
i++;
}
ans+=2;
l=l+i+1,r=r-i-1;
}
cout<<ans-1<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |