#include <bits/stdc++.h>
#define endl "\n"
#define int long long
using namespace std;
int q, n, P = 47, cnt = 1;
const int N = 1000000, M = 1000000007;
int p[N], h[N];
string s;
bool check_equal(int a, int b, int l) {
int ha = (h[a + l] - h[a] + M) % M;
int hb = (h[b + l] - h[b] + M) % M;
return 1LL * ha * p[b - a] % M == hb;
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> q;
p[0] = 1;
for (int i = 1; i < N; i++)
{
p[i] = p[i - 1] * P % M;
}
while(q--)
{
cin >> s;
cnt = 1;
n = s.size();
h[0] = 0;
for (int i = 1; i <= n; i++)
{
h[i] = (h[i-1] + (1LL * (s[i-1] - 'a' + 1) * p[i - 1] % M)) % M;
}
int l = 0, r = n, k = 1;
while(l < r && l + k < r - k)
{
if(check_equal(l, r - k, k))
{
l += k;
r -= k;
k = 1;
cnt += 2;
}
else k++;
}
cout << cnt << endl;
memset(h, 0, sizeof(h));
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
15960 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
15960 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
15960 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
15960 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |