#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define sc second
#define all(x) (x).begin(), (x).end()
#define Bit(x, y) ((x >> y) & 1)
#define inpFile(Task) freopen(Task".inp", "r", stdin);
#define outFile(Task) freopen(Task".out", "w", stdout);
#define submitFile(Task) inpFile(Task); outFile(Task);
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ull = unsigned ll;
const ll INF = (int)1e18, MOD1 = (int)1e9 + 7, MOD2 = (int)998244353;
template<class X, class Y> void maximize(X &a, const Y &b) { a = (a < b) ? b : a; }
template<class X, class Y> void minimize(X &a, const Y &b) { a = (a > b) ? b : a; }
template<class T> void add(T& a, T b, T mod) { a += b; if(a >= mod) a -= mod; }
template<class T> void sub(T& a, T b, T mod) { a -= b; if(a <= 0) a += mod; }
const int base = (int)353;
string T;
signed main() {
cin.tie(0)->ios_base::sync_with_stdio(0);
//submitFile("sixcup");
int numTest; cin >> numTest;
for(int iTest = 1; iTest <= numTest; iTest++) {
cin >> T;
int n = T.length();
int h1 = 0, h2 = 0, pw = 1, ans = 0;
int i = 0, j = n - 1;
while(i < j) {
h1 = (h1 * base + T[i]) % MOD1;
h2 = (T[j] * pw + h2) % MOD1;
pw = pw * base % MOD1;
if(h1 == h2) {
ans += 2;
h1 = h2 = 0;
pw = 1;
}
i++;
j--;
}
if(i <= j || h1 != 0) ans++;
cout << ans << "\n";
}
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... |