#include <bits/stdc++.h>
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
using namespace std;
const int N = 1e6 + 5, X = 997, M = 1e9 + 9;
int dp[N];
ll p[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
p[0] = 1;
for (int i = 1; i < N; i++)
p[i] = p[i - 1] * X;
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int n = s.size();
int ans = 0, i = 0;
bool work = true;
while (work) {
work = false;
ll h1 = 0, h2 = 0;
for (int j = 1; j * 2 <= n - i * 2; j++) {
h1 = h1 * X + s[j + i - 1];
h2 = h2 + s[n - j - i] * p[j - 1];
if (h1 == h2) {
i += j;
ans += 2;
work = true;
break;
}
}
}
if (i * 2 < n)
ans++;
cout << ans << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8184 KB |
Output is correct |
2 |
Correct |
9 ms |
8184 KB |
Output is correct |
3 |
Correct |
9 ms |
8056 KB |
Output is correct |
4 |
Correct |
9 ms |
8184 KB |
Output is correct |
5 |
Correct |
9 ms |
8184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8184 KB |
Output is correct |
2 |
Correct |
9 ms |
8184 KB |
Output is correct |
3 |
Correct |
9 ms |
8056 KB |
Output is correct |
4 |
Correct |
9 ms |
8184 KB |
Output is correct |
5 |
Correct |
9 ms |
8184 KB |
Output is correct |
6 |
Correct |
9 ms |
8184 KB |
Output is correct |
7 |
Correct |
9 ms |
8184 KB |
Output is correct |
8 |
Correct |
17 ms |
8184 KB |
Output is correct |
9 |
Correct |
9 ms |
8184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8184 KB |
Output is correct |
2 |
Correct |
9 ms |
8184 KB |
Output is correct |
3 |
Correct |
9 ms |
8056 KB |
Output is correct |
4 |
Correct |
9 ms |
8184 KB |
Output is correct |
5 |
Correct |
9 ms |
8184 KB |
Output is correct |
6 |
Correct |
9 ms |
8184 KB |
Output is correct |
7 |
Correct |
9 ms |
8184 KB |
Output is correct |
8 |
Correct |
17 ms |
8184 KB |
Output is correct |
9 |
Correct |
9 ms |
8184 KB |
Output is correct |
10 |
Correct |
10 ms |
8312 KB |
Output is correct |
11 |
Correct |
9 ms |
8184 KB |
Output is correct |
12 |
Correct |
10 ms |
8156 KB |
Output is correct |
13 |
Correct |
10 ms |
8184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
8184 KB |
Output is correct |
2 |
Correct |
9 ms |
8184 KB |
Output is correct |
3 |
Correct |
9 ms |
8056 KB |
Output is correct |
4 |
Correct |
9 ms |
8184 KB |
Output is correct |
5 |
Correct |
9 ms |
8184 KB |
Output is correct |
6 |
Correct |
9 ms |
8184 KB |
Output is correct |
7 |
Correct |
9 ms |
8184 KB |
Output is correct |
8 |
Correct |
17 ms |
8184 KB |
Output is correct |
9 |
Correct |
9 ms |
8184 KB |
Output is correct |
10 |
Correct |
10 ms |
8312 KB |
Output is correct |
11 |
Correct |
9 ms |
8184 KB |
Output is correct |
12 |
Correct |
10 ms |
8156 KB |
Output is correct |
13 |
Correct |
10 ms |
8184 KB |
Output is correct |
14 |
Correct |
47 ms |
17572 KB |
Output is correct |
15 |
Correct |
27 ms |
15692 KB |
Output is correct |
16 |
Correct |
37 ms |
19832 KB |
Output is correct |
17 |
Correct |
53 ms |
14776 KB |
Output is correct |