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 i64 = long long;
using namespace std;
struct Hash {
static constexpr int P = 1000000007, M = 29;
int n;
std::vector<int> a, pw;
Hash(std::string s) : n(s.size()), a(n + 1), pw(n + 1, 1) {
for (int i = 1; i <= n; i++)
pw[i] = 1LL * pw[i - 1] * M % P;
for (int i = 0; i < n; i++)
a[i + 1] = (1LL * a[i] * M + (s[i] - 'a' + 1)) % P;
}
int get(int l, int r) {
r++;
int res = a[r] - 1LL * pw[r - l] * a[l] % P;
if (res < 0)
res += P;
return res;
}
};
void solve() {
string s;
cin >> s;
int n = s.size();
int ans = 0;
int l = 0, r = n - 1;
Hash h(s);
for (int i = 0; i < n / 2; i++) {
if (h.get(l, i) == h.get(n - i - 1, r)) {
ans += 2;
l = i + 1;
r = n - i - 2;
}
}
ans += l <= r;
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
solve();
}
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... |