#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int M = 1e9 + 7;
struct Hash {
int x;
Hash(int x = 0): x(x) {}
friend Hash operator + (Hash u, const Hash& v) {
u.x += v.x;
if (u.x >= M) u.x -= M;
return u;
}
friend Hash operator - (Hash u, const Hash& v) {
u.x -= v.x;
if (u.x < 0) u.x += M;
return u;
}
friend Hash operator * (Hash u, const Hash& v) {
u.x = 1LL * u.x * v.x % M;
return u;
}
friend bool operator == (const Hash& u, const Hash& v) {
return u.x == v.x;
}
};
using ull = Hash;
const int N = 1e6 + 5;
string s;
ull h[N], pw[N], base = 31;
ull get(int l, int r) {
return h[r] - h[l - 1] * pw[r - l + 1];
}
int n;
int main() {
cin.tie(0)->sync_with_stdio(0); cout.tie(0);
pw[0] = 1;
for (int i = 1; i < N; ++i) {
pw[i] = pw[i - 1] * base;
}
int T; cin >> T;
while (T--) {
cin >> s;
n = s.size();
s = ' ' + s;
for (int i = 1; i <= n; ++i) {
h[i] = h[i - 1] * base + s[i] - 'a' + 1;
}
int last = 1, res = 0;
for (int i = 1; i <= n / 2; ++i) {
if (get(last, i) == get(n - i + 1, n - last + 1)) {
res += 2;
last = i + 1;
}
}
if (last <= (n + 1) / 2) {
res += 1;
}
cout << res << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8020 KB |
Output is correct |
2 |
Correct |
9 ms |
8148 KB |
Output is correct |
3 |
Correct |
9 ms |
8096 KB |
Output is correct |
4 |
Correct |
8 ms |
8020 KB |
Output is correct |
5 |
Correct |
8 ms |
8020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8020 KB |
Output is correct |
2 |
Correct |
9 ms |
8148 KB |
Output is correct |
3 |
Correct |
9 ms |
8096 KB |
Output is correct |
4 |
Correct |
8 ms |
8020 KB |
Output is correct |
5 |
Correct |
8 ms |
8020 KB |
Output is correct |
6 |
Correct |
9 ms |
8144 KB |
Output is correct |
7 |
Correct |
9 ms |
8148 KB |
Output is correct |
8 |
Correct |
9 ms |
8148 KB |
Output is correct |
9 |
Correct |
8 ms |
8076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8020 KB |
Output is correct |
2 |
Correct |
9 ms |
8148 KB |
Output is correct |
3 |
Correct |
9 ms |
8096 KB |
Output is correct |
4 |
Correct |
8 ms |
8020 KB |
Output is correct |
5 |
Correct |
8 ms |
8020 KB |
Output is correct |
6 |
Correct |
9 ms |
8144 KB |
Output is correct |
7 |
Correct |
9 ms |
8148 KB |
Output is correct |
8 |
Correct |
9 ms |
8148 KB |
Output is correct |
9 |
Correct |
8 ms |
8076 KB |
Output is correct |
10 |
Correct |
10 ms |
8148 KB |
Output is correct |
11 |
Correct |
9 ms |
8144 KB |
Output is correct |
12 |
Correct |
10 ms |
8148 KB |
Output is correct |
13 |
Correct |
9 ms |
8148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8020 KB |
Output is correct |
2 |
Correct |
9 ms |
8148 KB |
Output is correct |
3 |
Correct |
9 ms |
8096 KB |
Output is correct |
4 |
Correct |
8 ms |
8020 KB |
Output is correct |
5 |
Correct |
8 ms |
8020 KB |
Output is correct |
6 |
Correct |
9 ms |
8144 KB |
Output is correct |
7 |
Correct |
9 ms |
8148 KB |
Output is correct |
8 |
Correct |
9 ms |
8148 KB |
Output is correct |
9 |
Correct |
8 ms |
8076 KB |
Output is correct |
10 |
Correct |
10 ms |
8148 KB |
Output is correct |
11 |
Correct |
9 ms |
8144 KB |
Output is correct |
12 |
Correct |
10 ms |
8148 KB |
Output is correct |
13 |
Correct |
9 ms |
8148 KB |
Output is correct |
14 |
Correct |
134 ms |
10224 KB |
Output is correct |
15 |
Correct |
76 ms |
10092 KB |
Output is correct |
16 |
Correct |
129 ms |
11744 KB |
Output is correct |
17 |
Correct |
75 ms |
9200 KB |
Output is correct |