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 int ll
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
int pw[1000005], P = 41, mod = 998244353;
void solve(){
string s; cin >> s;
int n = s.size(), i = 0, j = n - 1, cur_sz = 0, ans = 0;
int lh = 0, rh = 0;
while(j - i > 0){
lh = (lh * P % mod + s[i] % mod);
rh = (rh + pw[cur_sz] * s[j]) % mod;
cur_sz++;
if(lh == rh){
cur_sz = lh = rh = 0;
ans += 2;
}
i++, j--;
}
if(cur_sz != 0 || n % 2) ans++;
cout << ans << '\n';
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
pw[0] = 1;
for(int i = 1; i <= 1000000; ++i) pw[i] = pw[i - 1] * P % mod;
int t = 1; 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... |