#include <bits/stdc++.h>
using namespace std;
#define int long long
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pp pop_back
#define endl '\n'
#define ff first
#define ss second
#define stop exit(0)
#define sz(x) (int)x.size()
#define pause system("pause")
#define all(x) (x).begin(), (x).end()
#define deb(x) cout << #x << "-" << x << endl
mt19937 mt(time(nullptr));
typedef char chr;
typedef string str;
typedef long long ll;
typedef vector<int> vii;
typedef pair<int, int> pii;
const long long INF = LLONG_MAX;
const int inf = INT_MAX;
const int mod = 1000003;
const int MOD = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,1,0,-1};
const double PI = 2 * acos(0.0);
const int N = 5e2+10;
const int P1 = MOD;
const int P2 = MOD+2;
int p[N];
int n;
string s;
int ans;
inline void test_case() {
cin >> s;
n = sz(s);
s = " " + s;
int l = 1; int r = n;
int lh = 0;
int rh = 0;
int len = 0;
ans = 0;
while (l <= r) {
if (l == r) {
lh = 0;
rh = 0;
len = 0;
ans++;
break;
}
lh *= P1;
lh %= P2;
lh += s[l];
rh += p[len]*s[r];
rh %= P2;
len++;
// cout << l << " " << r << " " << len << " "<<lh << " " << rh << endl;
if (lh == rh) {
ans+=2;
len = 0;
lh = rh = 0;
}
r--;
l++;
}
if (len) {
ans++;
}
cout << ans << endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
p[0] = 1;
for (int i = 1; i <= N-5; i++) {
p[i] = p[i-1]*P1;
}
int T = 1;
cin >> T;
while (T--) test_case();
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |