#include<bits/stdc++.h>
using namespace std;
long long mod,p,t,k,i,pwr[1000005],j,s1,s2,cur,ans,p1,mod1,pwr1[1000005],S1,S2;
string s;
int main(){
cin>>t;
p=31;
p1=29;
mod=1e9+7;
mod1=1e9+9;
pwr[1]=1;
pwr1[1]=1;
for(k=2;k<=1000005;k++){
pwr[k]=pwr[k-1]*p%mod;
pwr1[k]=pwr1[k-1]*p1%mod1;
}
while(t--){
cin>>s;
j=s.size()-1;
cur=1;s2=s1=S1=S2=0;
for(i=0;i<(s.size())/2;i++){
s1+=pwr[cur]*((int)s[i]-'a'+1)%mod;
S1+=pwr1[cur]*((int)s[i]-'a'+1)%mod1;
s1%=mod;
S1%=mod1;
s2=s2*p%mod+((int)s[j]-'a'+1);
S2=S2*p1%mod1+((int)s[j]-'a'+1);
s2%=mod;
S2%=mod1;
if(s1==s2 && S1==S2){
cur=1; s1=s2=0;
ans+=2; S1=S2=0;
}else cur++;
j--;
}
if(cur!=1 || s.size()%2==1) cout<<ans+1<<endl;
else cout<<ans<<endl;
ans=0;
}
}
Compilation message
palindromic.cpp: In function 'int main()':
palindromic.cpp:21:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<(s.size())/2;i++){
~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
16000 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
16000 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
16000 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
19 ms |
16000 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |