#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define st first
#define nd second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define len(x) (int)(x).size()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
template <typename T, typename H>
ostream& operator<<(ostream& os, pair<T, H> p){
return os << "(" << p.st << ", " << p.nd << ")";
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v){
os << "{";
for(int i = 0; i < v.size(); i++){
if(i != 0) os << ", ";
os << v[i];
}
os << "}";
return os;
}
#ifdef DEBUG
#define fastio()
#define debug(x...) cerr << "[" << #x << "]: ", [](auto... $) {((cerr << $ << ", "), ...); }(x), cerr << '\n'
#else
#define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define debug(x...)
#endif
constexpr int P = 271;
constexpr int MOD = 1e9+7;
constexpr int N = 1e6+7;
string s;
int pows[N];
void solve(){
cin >> s;
int n = len(s);
int ans = 0;
int left = 0;
int right = n-1;
int sajz = 0;
int lh = 0;
int rh = 0;
while(left < right){
// update lh
lh = ((ll)lh * (ll)P) % MOD;
lh = ((ll)lh + (ll)s[left]) % MOD;
// update rh
int to_add = ((ll)pows[sajz] * (ll)s[right]) % MOD;
rh = ((ll)rh + (ll)to_add) % MOD;
sajz++;
if(lh == rh){
ans += 2;
lh = 0;
rh = 0;
sajz = 0;
}
left++;
right--;
}
if(sajz != 0 || left == right) ans++;
cout << ans << '\n';
}
int32_t main(){
fastio();
pows[0] = 1;
for(int i = 1; i < N; i++) pows[i] = ((ll)pows[i-1] * (ll)P) % MOD;
int tt = 1;
cin >> tt;
while(tt--) solve();
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... |