#include<iostream>
#include<algorithm>
#include<string>
#include<bitset>
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
const int N = 1e6 + 16, mod = 1e9 + 7, base = 331;
const ll mod2 = (ll)mod * mod;
int n;
string s;
ll pw[N], hsh[N];
ll get(int l, int r) {
return (hsh[r] - hsh[l - 1] * pw[r - l + 1] + mod2) % mod;
}
int main() {
cin.tie(NULL)->sync_with_stdio(false);
pw[0] = 1;
for (int i = 1; i < N; ++i)
pw[i] = pw[i - 1] * base % mod;
int test; cin >> test; while (test--) {
cin >> s; n = s.size();
s = " " + s;
for (int i = 1; i <= n; ++i)
hsh[i] = (hsh[i - 1] * base + s[i]) % mod;
int l(1), r(n), len(0), ans(0);
while (l < r) {
++len;
if (get(l - len + 1, l) == get(r, r + len - 1))
ans += 2, len = 0;
++l, --r;
}
cout << ans + (len > 0 || l == r) << '\n';
}
}
/** /\_/\
* (= ._.)
* / >0 \>1
**/
/*
==================================================+
INPUT: |
--------------------------------------------------|
4
bonobo
deleted
racecar
racecars
--------------------------------------------------|
==================================================+
OUTPUT: |
--------------------------------------------------|
3
5
7
1
--------------------------------------------------|
==================================================+
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8140 KB |
Output is correct |
2 |
Correct |
7 ms |
8076 KB |
Output is correct |
3 |
Correct |
9 ms |
8144 KB |
Output is correct |
4 |
Correct |
10 ms |
8060 KB |
Output is correct |
5 |
Correct |
9 ms |
8140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8140 KB |
Output is correct |
2 |
Correct |
7 ms |
8076 KB |
Output is correct |
3 |
Correct |
9 ms |
8144 KB |
Output is correct |
4 |
Correct |
10 ms |
8060 KB |
Output is correct |
5 |
Correct |
9 ms |
8140 KB |
Output is correct |
6 |
Correct |
9 ms |
8140 KB |
Output is correct |
7 |
Correct |
8 ms |
8140 KB |
Output is correct |
8 |
Correct |
9 ms |
8140 KB |
Output is correct |
9 |
Correct |
8 ms |
8192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8140 KB |
Output is correct |
2 |
Correct |
7 ms |
8076 KB |
Output is correct |
3 |
Correct |
9 ms |
8144 KB |
Output is correct |
4 |
Correct |
10 ms |
8060 KB |
Output is correct |
5 |
Correct |
9 ms |
8140 KB |
Output is correct |
6 |
Correct |
9 ms |
8140 KB |
Output is correct |
7 |
Correct |
8 ms |
8140 KB |
Output is correct |
8 |
Correct |
9 ms |
8140 KB |
Output is correct |
9 |
Correct |
8 ms |
8192 KB |
Output is correct |
10 |
Correct |
9 ms |
8256 KB |
Output is correct |
11 |
Correct |
9 ms |
8268 KB |
Output is correct |
12 |
Correct |
8 ms |
8152 KB |
Output is correct |
13 |
Correct |
9 ms |
8192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
8140 KB |
Output is correct |
2 |
Correct |
7 ms |
8076 KB |
Output is correct |
3 |
Correct |
9 ms |
8144 KB |
Output is correct |
4 |
Correct |
10 ms |
8060 KB |
Output is correct |
5 |
Correct |
9 ms |
8140 KB |
Output is correct |
6 |
Correct |
9 ms |
8140 KB |
Output is correct |
7 |
Correct |
8 ms |
8140 KB |
Output is correct |
8 |
Correct |
9 ms |
8140 KB |
Output is correct |
9 |
Correct |
8 ms |
8192 KB |
Output is correct |
10 |
Correct |
9 ms |
8256 KB |
Output is correct |
11 |
Correct |
9 ms |
8268 KB |
Output is correct |
12 |
Correct |
8 ms |
8152 KB |
Output is correct |
13 |
Correct |
9 ms |
8192 KB |
Output is correct |
14 |
Correct |
128 ms |
26480 KB |
Output is correct |
15 |
Correct |
80 ms |
22804 KB |
Output is correct |
16 |
Correct |
133 ms |
28700 KB |
Output is correct |
17 |
Correct |
69 ms |
18360 KB |
Output is correct |