#include <bits/stdc++.h>
using namespace std;
constexpr int p = 31;
constexpr int mod = 1e9 + 7;
void solve() {
string a;
cin >> a;
int n = a.size();
vector<int> hash(n + 1);
for (int i = 0; i < n; i++) {
hash[i + 1] = (hash[i] + (a[i] - 'a' + 1) * p) % mod;
}
int tl = 0, tr = n, l = 1, r = n;
int pre = 0, suf = 0, ans = 0;
string s;
while (l < r) {
s.push_back(a[l]);
pre = hash[l++];
suf = hash[n] - hash[--r];
if (pre == suf) {
s.clear();
ans += 2;
}
}
if (l <= r || !s.empty()) {
ans++;
}
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... |