#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
using pii = pair<ll,ll>;
#define x first
#define y second
ll p=31;
ll mod=1000000007;
ll ppow[1000001];
void puz(){
ppow[0]=1;
for(int i=1;i<=1000000;i++){
ppow[i]=(ppow[i-1]*p)%mod;
}
return;
}
void has(vector<ll>& has,string s){
has[0]=0;
for(int i=1;i<=s.size();i++){
has[i]=(has[i-1]+((s[i-1]-'a'+1)*ppow[i-1]))%mod;
}
return;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t;cin >> t;
puz();
while(t--){
string s;cin >> s;
ll n=s.size();
vector<ll> hash(n+1);
has(hash,s);
ll l=0,ans=0;
for(ll i=0;i<n;i++){
cout << l << " " << i << endl;
if(i>=(n-1)/2){
if(n%2==0){
if(l!=i) ans++;
break;
}
else{
ans++;
break;
}
}
ll h1=(hash[i+1]-hash[l]+mod)%mod;
ll h2=(hash[n-l]-hash[n-1-i]+mod)%mod;
if((h1*ppow[n-1-i])%mod==(h2*ppow[l])%mod){
ans+=2;
l=i+1;
cout << ans << endl;
}
}
cout << ans << endl;
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |