This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl '\n'
#define pb push_back
#define mk make_pair
#define sz size()
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define kill(x) return cout << x << endl, void();
#define int ll
#define pii pair <int, int>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
const int N = 1e6 + 5;
const int MOD = 998244353, INF = 2e9, sq = 450;
int ps[N], pw[N];
int mab = 27;
int hsh (int l, int r)
{
return (ps[r] - (l == 0 ? 0 : ps[l - 1]) * pw[r - l + 1] % MOD + MOD) % MOD;
}
void Solve ()
{
string s;
cin >> s;
int n = s.sz, l = 0, ans = 0;
ps[0] = s[0] - 'a' + 1;
for (int i = 1; i < n; i++)
ps[i] = (ps[i - 1] * mab + (s[i] - 'a' + 1)) % MOD;
for (int r = l; r < n - l; r++)
{
if (hsh (l, r) == hsh (n - r - 1, n - l - 1))
{
ans += 2;
if (r == n - l - 1)
ans--;
l = r + 1;
}
}
cout << ans << endl;
}
int32_t main ()
{
pw[0] = 1;
for (int i = 1; i < N; i++)
pw[i] = pw[i - 1] * mab % MOD;
ios::sync_with_stdio (0), cin.tie (0), cout.tie (0);
int tt = 1;
cin >> tt;
while (tt--)
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... |