#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 1e6 + 5;
const ll m1 = 1e15 + 1, m2 = 1e15 + 3;
ll tc, n, l1, l2, r1, r2, pw1, pw2;
string s;
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> tc;
while(tc--){
cin >> s; n = s.size();
l1 = l2 = r1 = r2 = 0; pw1 = pw2 = 1;
int ans = 0, cnt = 0;
for(int i = 0; i < n / 2; i++){
l1 = (l1 * 26 + s[i] - 'a') % m1;
l2 = (l2 * 26 + s[i] - 'a') % m2;
r1 = (r1 + pw1 * (s[n - 1 - i] - 'a')) % m1;
r2 = (r2 + pw2 * (s[n - 1 - i] - 'a')) % m2;
if(l1 == r1 && l2 == r2){
ans += 2; cnt = 0;
l1 = l2 = r1 = r2 = 0;
pw1 = pw2 = 1;
}
else {
cnt++;
pw1 = pw1 * 26 % m1;
pw2 = pw2 * 26 % m2;
}
}
if(n & 1 || cnt) ans++;
cout << ans << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
412 KB |
Output is correct |
14 |
Correct |
60 ms |
11168 KB |
Output is correct |
15 |
Correct |
38 ms |
6524 KB |
Output is correct |
16 |
Correct |
64 ms |
10636 KB |
Output is correct |
17 |
Correct |
34 ms |
6048 KB |
Output is correct |