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;
const int mxN = 1e6 + 6;
const int base = 53;
const int MOD = 1e9 + 7;
int H[mxN], P[mxN];
int get_hash(int l, int r){
return (1LL * H[r] - 1LL * H[l - 1] * P[r - l + 1] % MOD + MOD) % MOD;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
P[0] = 1;
for(int i = 1;i < mxN;++i){
P[i] = 1LL * P[i - 1] * base % MOD;
}
int t;
cin >> t;
while(t--){
string str;
cin >> str;
int n = (int)str.size();
str = '$' + str;
for(int i = 1;i <= n;++i){
H[i] = (1LL * H[i - 1] * base % MOD + (str[i] - 'a' + 1)) % MOD;
}
int L = 1;
int res = 0;
while(L <= n / 2){
int p = L;
while(p <= n / 2 && get_hash(L, p) != get_hash(n - p + 1, n - L + 1)){
p++;
}
if(p > n / 2)break;
res += 2;
L = p + 1;
}
if(L <= n / 2 + n % 2)res++;
cout << res << '\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... |