// Template generated by Clank
#include<bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define all(x) x.begin(), x.end()
#define BOOST cin.tie(NULL); ios_base::sync_with_stdio(false);
// #define int ll
typedef long long ll;
struct Hash{
ll mod;
ll p;
int n;
string s;
vector<ll> h;
vector<ll> pk;
Hash(string &ins, ll inp, ll inmod) : p(inp), mod(inmod) {
s = "#" + ins;
n = s.size();
h.resize(n);
pk.resize(n);
pk[0] = 1;
for(int i = 1; i < n; i++){
pk[i] = (pk[i - 1] * p) % mod;
h[i] = (h[i - 1] * p + s[i] - 'a' + 1) % mod;
}
}
ll seg(int l, int r){
l++; r++;
ll tmp = (h[r] - (h[l - 1] * pk[r - l + 1])) % mod;
if(tmp < 0) tmp += mod;
return tmp;
}
};
void solve(){
string s; cin >> s;
int n = s.size();
int last_good = 0;
int ans = 0;
Hash h1(s, 43, 888173173);
for(int i = 0; i < n / 2; i++){
if(h1.seg(last_good, i) == h1.seg(n - i - 1, n - last_good - 1)){
ans += 2;
last_good = i + 1;
}
}
if(n&1 || last_good < n/2) ans++;
cout << ans << "\n";
}
int32_t main(){
BOOST;
int q; cin >> q;
while(q--)
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... |