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 task "a"
#define se second
#define fi first
#define ll long long
#define ii pair<ll, ll>
const long mxN = 2e5 + 7, MOD = 1e9 + 7;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//freopen(task".INP", "r", stdin);
//freopen(task".OUT", "w", stdout);
int tst;
cin >> tst;
while (tst--)
{
string s;
cin >> s;
int l = 0, r = s.size() - 1, ans = 0;
ll lt = 0, rt = 0, base = 1;
while (1)
{
lt = (lt * 31 + s[l] - 'a' + 1) % MOD;
rt = (base * (s[r] - 'a' + 1) + rt) % MOD;
base = base * 31 % MOD;
if (lt == rt)
{
ans += (l < r) + 1;
lt = rt = 0;
base = 1;
if (l + 1 >= r)
break;
}
l++;
r--;
}
cout << ans << '\n';
}
}
# | 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... |