#include <bits/stdc++.h>
using namespace std;
#define egal(a, b, c, d) ()
const int N = 1e6 + 7, BASE = 'z' - 'a' + 1;
int MOD[2];
int paw[N][2], hesh[N][2];
string s;
int abs(int val, bool mod) {
if (val < 0)
return val + MOD[mod];
return val;
}
int main()
{
MOD[0] = 1e9 + 7, MOD[1] = 1e9 + 9;
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
//hatz putere ca ne trebe impreuna cu hash sa bagam egal(i,j,k,t)
paw[0][0] = paw[0][1] = 1;
for (int i = 1; i < N; ++i)
for (int t = 0; t < 2; ++t)
paw[i][t] = paw[i - 1][t] * BASE % MOD[t];
while (t--) {
cin >> s;
///mare hashuri de sa moara dushmanii
int n = s.size();
hesh[1][0] = hesh[1][1] = (s[0] - 'a');
for (int i = 1; i < n; ++i)
for (int t = 0; t < 2; ++t)
hesh[i + 1][t] = hesh[i][t] * BASE + (s[i] - 'a');
int j(1), ans(0);//unde ai ramas, adeverat bossule
for (int i = 1; i <= n / 2; ++i) {
if (abs(hesh[i][0] - hesh[j - 1][0] * paw[i - j + 1][0] % MOD[0], 0) == abs(hesh[n - j + 1][0] - hesh[n - i][0] * paw[i - j + 1][0] % MOD[0], 0) && abs(hesh[i][1] - hesh[j - 1][1] * paw[i - j + 1][1] % MOD[1], 1) == abs(hesh[n - j + 1][1] - hesh[n - i][1] * paw[i - j + 1][1] % MOD[1], 1))
ans += 2, j = i + 1;
}
cout << ans + (2 * j - 2 != n) << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
8192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
8192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
8192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
8192 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |