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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
using ull = unsigned long long;
const int N = 1e6 + 5, B = 331;
ull pw[N];
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
pw[0] = 1;
for (int i = 1; i < N; ++i) {
pw[i] = pw[i - 1] * B;
}
int t; cin >> t;
while (t--) {
string s; cin >> s;
int n = s.size(), res = 0, l, r, len;
ull a = 0, b = 0;
for (l = 0, r = n - 1, len = 0; l < r; ++l, --r) {
a = a * B + s[l] - 'a' + 1;
b = (s[r] - 'a' + 1) * pw[len] + b;
if (a == b) {
a = b = len = 0;
res += 2;
} else {
++len;
}
}
cout << res + (n & 1 || len) << "\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... |