#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
int m=1000000007;
lli cal(lli p,lli n)
{
lli b=0,ans=1,a=n;
while((1LL<<b)<=p)
{
if(bit(p,b))
ans=(ans*a)%m;
a=(a*a)%m;
b++;
}
return(ans);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test=1;
cin>>test;
for(;test>0;--test)
{
lli n,p=131,c=0,l=0,la=0,r,ls=0,rs=0;
string s;
cin>>s;
n=s.size();
r=n-1;
while(l<=r)
{
ls=(ls+((s[l]-'a')*cal(l-la+1,p))%m)%m;
rs=(rs*p+((s[n-1-la-(l-la)]-'a')*p)%m)%m;
if(rs==ls)
{
rs=0;
ls=0;
c+=2;
la=l+1;
l=la;
r=n-1-la-(l-la)-1;
}
else
{
r--;
l++;
}
if(l>r)
{
c++;
break;
}
}
cout<<c<<endl;
}
return(0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |