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>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll mod=(ll)1e17-3;
int t,n;
char s[1000010];
int main() {
cin>>t;
int i,j;
while(t--) {
cin>>s;
n=strlen(s);
j=n;
ll hl=0,hr=0,pw=1,cnt=0;
for(i=0;i<n/2;i++) {
hl=(26*hl+s[i]-'a')%mod;
hr=(hr+(s[n-i-1]-'a')*pw%mod)%mod;
if(hl==hr) {
cnt+=2;
j=i;
hl=hr=0; pw=1;
} else pw=26*pw%mod;
}
if(n%2||j!=n/2-1) cnt++;
cout<<cnt<<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... |