#include<bits/stdc++.h>
#define ll long long
#define ii pair < int , int >
#define iii pair < int , ii>
#define iv pair < ii , ii >
#define fi first
#define se second
#define y1 dkjfd
using namespace std;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
const int base = 310;
string s;
int pre[N], pw[N];
vector < int > ans;
int mul(int x, int y)
{
return 1LL * x * y % mod;
}
int add(int x, int y)
{
return ((1LL * x + y) % mod + mod) % mod;
}
int get(int l, int r)
{
return add(pre[r], - mul(pre[l - 1], pw[r - l + 1]));
}
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("wormsort.in" , "r" , stdin);
// freopen("wormsort.out" , "w" , stdout);
pw[0] = 1;
for(int i = 1; i <= 1e6; i++)
pw[i] = mul(pw[i - 1], base);
int t; cin >> t;
while(t--)
{
cin >> s;
int n = s.size();
s = '#' + s;
for(int i = 1; i <= n; i++)
pre[i] = add(mul(pre[i - 1], base), s[i]);
int ans = 0;
int i = 1;
int d = 1;
while(true)
{
while(get(i, i + d - 1) != get(n - i - d + 2, n - i + 1)) d++;
// cout << i << " " << d << endl;
if(i != n - i - d + 2) ans += 2;
else ans += 1;
i += d;
d = 1;
if(i > n / 2 + 1) break;
}
cout << ans << '\n';
}
}
Compilation message
palindromic.cpp:32:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
32 | main()
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
4188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
4188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
4188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
4188 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |