#include<bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn=1000000+10;
bool check(long long a){
for(int i=2;i*i<=a;i++){
if(a%i==0){
return 0;
}
}
return 1;
}
int getav(long long a){
while(check(a)==0){
a++;
}
return a;
}
long long mod=getav(rng()%100000000+993847562),base=getav(rng()%200+1000),mp[maxn];
void aval(){
mp[0]=1;
for(int i=1;i<maxn;i++){
mp[i]=1ll*mp[i-1]*base%mod;
}
}
void solve(){
string s;
cin>>s;
int n=s.size();
int mid=n/2;
string first,second;
for(int i=0;i<mid;i++){
first.push_back(s[i]);
}
for(int i=mid+(n&1);i<n;i++){
second.push_back(s[i]);
}
int i=0,j=(int)second.size()-1;
int res=0;
long long hash1=0,hash2=0;
int last=0;
for(int asd=0;asd<(int)first.size();asd++){
hash1+=mp[i-last]*first[i];
hash2=hash2*base+second[j];
hash1%=mod;
hash2%=mod;
//cout<<asd<<" "<<first[i]<<" "<<second[j]<<" "<<hash1<<" "<<hash2<<endl;
if(hash1==hash2){
res+=2;
hash1=hash2=0;
last=asd+1;
}
i++;
j--;
}
res++;
cout<<res<<"\n";
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("inp.txt","r",stdin);
aval();
int t;
cin>>t;
for(int asd=0;asd<t;asd++){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
8284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
8284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
8284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
8284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |