#include<bits/stdc++.h>
using namespace std;
long long mod,p,t,k,i,pwr[1000005],j,s1,s2,cur,ans;
string s;
int main(){
cin>>t;
p=31;
mod=1e9+7;
pwr[1]=1;
for(k=2;k<=1000005;k++){
pwr[k]=pwr[k-1]*p%mod;
}
while(t--){
cin>>s;
j=s.size()-1;
cur=1;
for(i=0;i<(s.size())/2;i++){
s1+=pwr[cur]*((int)s[i]-'a'+1);
s1%=mod;
s2=s2*p%mod+((int)s[j]-'a'+1);
s2%=mod;
if(s1==s2){
cur=1; s1=s2=0;
ans+=2;
}else cur++;
j--;
} s2=s1=0;
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:17:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(i=0;i<(s.size())/2;i++){
~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
8192 KB |
Output is correct |
2 |
Correct |
14 ms |
8192 KB |
Output is correct |
3 |
Correct |
13 ms |
8192 KB |
Output is correct |
4 |
Correct |
14 ms |
8192 KB |
Output is correct |
5 |
Correct |
13 ms |
8192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
8192 KB |
Output is correct |
2 |
Correct |
14 ms |
8192 KB |
Output is correct |
3 |
Correct |
13 ms |
8192 KB |
Output is correct |
4 |
Correct |
14 ms |
8192 KB |
Output is correct |
5 |
Correct |
13 ms |
8192 KB |
Output is correct |
6 |
Correct |
13 ms |
8192 KB |
Output is correct |
7 |
Correct |
13 ms |
8192 KB |
Output is correct |
8 |
Correct |
13 ms |
8192 KB |
Output is correct |
9 |
Correct |
14 ms |
8064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
8192 KB |
Output is correct |
2 |
Correct |
14 ms |
8192 KB |
Output is correct |
3 |
Correct |
13 ms |
8192 KB |
Output is correct |
4 |
Correct |
14 ms |
8192 KB |
Output is correct |
5 |
Correct |
13 ms |
8192 KB |
Output is correct |
6 |
Correct |
13 ms |
8192 KB |
Output is correct |
7 |
Correct |
13 ms |
8192 KB |
Output is correct |
8 |
Correct |
13 ms |
8192 KB |
Output is correct |
9 |
Correct |
14 ms |
8064 KB |
Output is correct |
10 |
Correct |
19 ms |
8320 KB |
Output is correct |
11 |
Correct |
16 ms |
8192 KB |
Output is correct |
12 |
Correct |
21 ms |
8192 KB |
Output is correct |
13 |
Correct |
18 ms |
8320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
8192 KB |
Output is correct |
2 |
Correct |
14 ms |
8192 KB |
Output is correct |
3 |
Correct |
13 ms |
8192 KB |
Output is correct |
4 |
Correct |
14 ms |
8192 KB |
Output is correct |
5 |
Correct |
13 ms |
8192 KB |
Output is correct |
6 |
Correct |
13 ms |
8192 KB |
Output is correct |
7 |
Correct |
13 ms |
8192 KB |
Output is correct |
8 |
Correct |
13 ms |
8192 KB |
Output is correct |
9 |
Correct |
14 ms |
8064 KB |
Output is correct |
10 |
Correct |
19 ms |
8320 KB |
Output is correct |
11 |
Correct |
16 ms |
8192 KB |
Output is correct |
12 |
Correct |
21 ms |
8192 KB |
Output is correct |
13 |
Correct |
18 ms |
8320 KB |
Output is correct |
14 |
Correct |
551 ms |
19044 KB |
Output is correct |
15 |
Correct |
301 ms |
14568 KB |
Output is correct |
16 |
Correct |
526 ms |
18808 KB |
Output is correct |
17 |
Correct |
293 ms |
14040 KB |
Output is correct |