#include <iostream>
using namespace std;
#define ll long long
const ll MOD = 1e9 + 7;
const ll base = 99999989;
int t, n;
string s;
int main() {
cin.tie(nullptr);
cout.tie(nullptr);
ios_base::sync_with_stdio(false);
cin >> t;
while (t--) {
cin >> s;
n = s.length();
s = " " + s;
int ans = 1;
ll one = 0, two = 0, p = 1;
for (int i = 1; i * 2 <= n; ++i) {
one = (one * base + s[i] - 'a' + 1) % MOD;
two = ((ll)(s[n - i + 1] - 'a' + 1) * p + two) % MOD;
p = p * base % MOD;
if (one == two) {
if (i * 2 == n) --ans;
one = two = 0;
p = 1;
ans += 2;
}
}
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... |