#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fr first
#define sc second
const long long INF=1e17,N=1e6+6,mod=1e9+7;
int p=31;
int h[N],hsh[N];
int hesh(int l, int r){
return (((hsh[r]-hsh[l-1]+mod)%mod)*h[N-r])%mod;
}
deque<int> c[29];
void solve(){
string s;cin>>s;int n=s.size();
h[0]=1;
for(int i=1;i<N;i++){
h[i]=(h[i-1]*p)%mod;
}
for(int i=1;i<=(int)s.size();i++){
hsh[i]=(hsh[i-1]+((s[i-1]-'a'+1)*h[i-1])%mod)%mod;
}
int ans=0;
for(int i=0;i<(n)/2;i++){
int j=i;
int l=n-i-1;
bool ok=0;
for(;j<(n)/2;j++,l--){
//cout<<i<<' '<<j<<':'<<l<<' '<<n-i-1<<endl;
//cout<<hesh(i+1,j+1)<<' '<<hesh(l+1,n-i)<<endl;
//
if(hesh(i+1,j+1)==(hesh(l+1,n-i))){
ok=1;
ans+=2;
if(n%2==0 && j==n/2-1) ans--;
break;
}
//if(j==n/2) ans++;
}
//if(!ok) ans++;
i=j;
}
cout<<ans+1<<endl;
}
main(){
int T=1;
cin>>T;
while(T--){
solve();
}
}
/*
11
7958 4722 9704 6995 1052 5269 7479 8238 6423 7918 866
7659 2498 8486 1196 7462 6633 2158 2022 1146 8392 3037
*/
Compilation message
palindromic.cpp: In function 'void solve()':
palindromic.cpp:27:8: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
27 | bool ok=0;
| ^~
palindromic.cpp: At global scope:
palindromic.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
46 | main(){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
9564 KB |
Output is correct |
2 |
Correct |
45 ms |
9560 KB |
Output is correct |
3 |
Correct |
23 ms |
9560 KB |
Output is correct |
4 |
Correct |
44 ms |
9564 KB |
Output is correct |
5 |
Correct |
45 ms |
9564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
9564 KB |
Output is correct |
2 |
Correct |
45 ms |
9560 KB |
Output is correct |
3 |
Correct |
23 ms |
9560 KB |
Output is correct |
4 |
Correct |
44 ms |
9564 KB |
Output is correct |
5 |
Correct |
45 ms |
9564 KB |
Output is correct |
6 |
Correct |
45 ms |
9560 KB |
Output is correct |
7 |
Correct |
28 ms |
9564 KB |
Output is correct |
8 |
Correct |
45 ms |
9564 KB |
Output is correct |
9 |
Correct |
45 ms |
9564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
9564 KB |
Output is correct |
2 |
Correct |
45 ms |
9560 KB |
Output is correct |
3 |
Correct |
23 ms |
9560 KB |
Output is correct |
4 |
Correct |
44 ms |
9564 KB |
Output is correct |
5 |
Correct |
45 ms |
9564 KB |
Output is correct |
6 |
Correct |
45 ms |
9560 KB |
Output is correct |
7 |
Correct |
28 ms |
9564 KB |
Output is correct |
8 |
Correct |
45 ms |
9564 KB |
Output is correct |
9 |
Correct |
45 ms |
9564 KB |
Output is correct |
10 |
Correct |
47 ms |
9816 KB |
Output is correct |
11 |
Correct |
29 ms |
9820 KB |
Output is correct |
12 |
Correct |
47 ms |
9816 KB |
Output is correct |
13 |
Correct |
47 ms |
9820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
9564 KB |
Output is correct |
2 |
Correct |
45 ms |
9560 KB |
Output is correct |
3 |
Correct |
23 ms |
9560 KB |
Output is correct |
4 |
Correct |
44 ms |
9564 KB |
Output is correct |
5 |
Correct |
45 ms |
9564 KB |
Output is correct |
6 |
Correct |
45 ms |
9560 KB |
Output is correct |
7 |
Correct |
28 ms |
9564 KB |
Output is correct |
8 |
Correct |
45 ms |
9564 KB |
Output is correct |
9 |
Correct |
45 ms |
9564 KB |
Output is correct |
10 |
Correct |
47 ms |
9816 KB |
Output is correct |
11 |
Correct |
29 ms |
9820 KB |
Output is correct |
12 |
Correct |
47 ms |
9816 KB |
Output is correct |
13 |
Correct |
47 ms |
9820 KB |
Output is correct |
14 |
Correct |
271 ms |
19012 KB |
Output is correct |
15 |
Correct |
146 ms |
18828 KB |
Output is correct |
16 |
Correct |
252 ms |
18844 KB |
Output is correct |
17 |
Correct |
163 ms |
15524 KB |
Output is correct |