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 mod 1000000007
int main()
{
int t, p = 47;
cin>>t;
vector<ll> pw(1000001);
pw[0] = 1;
for (int i = 1; i <= 1000001; i++){
pw[i] = (pw[i - 1] * p) % mod;
}
for (int it = 0; it < t; it++){
string s;
cin>>s;
int l = 0, lind = -1, r = s.size() - 1;
ll lhash = 0, rhash = 0, c = 0;
while (l < r){
lind++;
lhash += s[l] * pw[lind];
lhash %= mod;
rhash = rhash * p + s[r];
rhash %= mod;
if (lhash == rhash){
c += 2;
lhash = 0;
rhash = 0;
lind = -1;
}
l++;
r--;
}
if (l == r || lhash != 0 || rhash != 0){
c++;
}
cout<<c<<"\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... |