This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
long long n,m,base=311,k,t,mod=1e9+7,has[1000005],p[1000005];
long long get(long long x,long long y)
{
return (has[y]-has[x-1]*p[y-x+1]+mod*mod)%mod;
}
string s;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>t;
while(t--)
{
long long ans=0;
cin>>s;
n=s.length();
s=' '+s;
p[0]=1;
for(int i=1;i<=n;i++)
{
p[i]=(p[i-1]*base)%mod;
has[i]=(has[i-1]*base+s[i]-'a'+1)%mod;
}
long long neil=1,nei=n;
for(int i=1;i<=n/2;i++)
{
if(get(neil,i)==get(nei-(i-neil),nei)) ans+=2,neil=i+1,nei=n-i;
}
if(neil<=nei) ans++;
cout<<ans<<'\n';
}
}
# | 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... |