#include <iostream>
using namespace std;
#define int long long
int hsh[1<<20], pw[1<<20], mod = 998244353;
int get(int l, int r){
return (hsh[r] - hsh[l - 1] * pw[r - l + 1] % mod + mod) % mod;
}
void solve(){
string s;
cin>>s;
int n = s.size();
for (int i=pw[0]=1;i<=n;i++){
hsh[i] = (hsh[i-1] * 256 + s[i - 1]) % mod;
pw[i] = pw[i-1] * 256 % mod;
}
int L = 1, R = n, Ans = 0, t = 1;
while (t){
t = 0;
for (int i=1;i * 2 <= R - L + 1 and !t;i++){
if (get(L, L + i - 1) == get(R - i + 1, R))
t = 1, Ans += 2, L += i, R -= i;
}
if (!t and R >= L)
Ans++;
}
cout<<Ans<<'\n';
}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int t;
cin>>t;
while (t--)
solve();
}
| # | 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... |