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;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 1e6 + 5;
const ll m1 = 1e15 + 1, m2 = 1e15 + 3;
ll tc, n, l1, l2, r1, r2, pw1, pw2;
string s;
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> tc;
while(tc--){
cin >> s; n = s.size();
l1 = l2 = r1 = r2 = 0; pw1 = pw2 = 1;
int ans = 0, cnt = 0;
for(int i = 0; i < n / 2; i++){
l1 = (l1 * 26 + s[i] - 'a') % m1;
l2 = (l2 * 26 + s[i] - 'a') % m2;
r1 = (r1 + pw1 * (s[n - 1 - i] - 'a')) % m1;
r2 = (r2 + pw2 * (s[n - 1 - i] - 'a')) % m2;
if(l1 == r1 && l2 == r2){
ans += 2; cnt = 0;
l1 = l2 = r1 = r2 = 0;
pw1 = pw2 = 1;
}
else {
cnt++;
pw1 = pw1 * 26 % m1;
pw2 = pw2 * 26 % m2;
}
}
if(n & 1 || cnt) ans++;
cout << ans << '\n';
}
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... |