#include<bits/stdc++.h>
#define fi first
#define se second
#define FOR(i, k, n) for(int i = k; i <= n; i++)
#define FOR1(i, k, n) for(int i = k; i >= n; i--)
#define pb push_back
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define ll long long
#define vll vector<ll>
#define pll pair<ll, ll>
#define re return 0
#define mii map<int, int>
#define input "ALONE.inp"
#define output "ALONE.out"
#define rf freopen(input, "r", stdin); freopen(output, "w", stdout)
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
const int base = 998244353;
const int base1 = 31;
const int SZ = 320;
const ll INF = 1e18;
void add(int &a, int b)
{
a += b;
if(a >= mod) a -= mod;
if(a < 0) a += mod;
}
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r)
{
return uniform_int_distribution<int>(l, r) (rd);
}
int Hash[maxn], B[maxn];
int get(int l, int r)
{
return (Hash[r] - 1ll * Hash[l - 1] * B[r - l + 1] + 1ll * mod * mod) % mod;
}
int main()
{
fastio;
int test;
cin >> test;
B[0] = 1;
FOR(i, 1, 1000000)
B[i] = (1ll * B[i - 1] * base) % mod;
while(test--)
{
string s;
cin >> s;
int n = s.size();
s = ' ' + s;
FOR(i, 1, n)
Hash[i] = (1ll * Hash[i - 1] * base + s[i]) % mod;
int l = 1, r = n;
int vtl = 1, vtr = n;
int ans = 0;
int anr = n + 1, anl = 0;
while(vtl < vtr)
{
if(get(l, vtl) == get(vtr, r))
{
ans += 2;
l = vtl + 1;
r = vtr - 1;
anl = vtl;
anr = vtr;
}
vtl++;
vtr--;
}
ans++;
if(anl + 1 == anr)
ans--;
cout << ans << "\n";
}
re;
}
| # | 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... |