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;
typedef long long ll;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
// #pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define int long long
#define lowbit(x) x&-x
const int maxn = 1e6 + 5;
const int INF = 4e18;
const int N = 998244353;
const int A = 238435927;
void solve(){
string s;
cin>>s;
int n = s.size();
vector<int> h(n), p(n);
h[0] = s[0], p[0] = 1;
for(int i = 1; i < n; i++){
p[i] = p[i - 1] * A % N;
h[i] = (h[i - 1] * A + s[i]) % N;
}
int ans = 0;
auto get = [&](int l, int r) -> int {
return (h[r] - (l ? h[l - 1] * p[r - l + 1] % N : 0) + N) % N;
};
int l = 0;
for(int i = 0; i < n; i++){
int a = get(l, i), b = get(n - i - 1, n - l - 1);
if(a == b){
ans++;
l = i + 1;
}
}
cout<<ans<<"\n";
}
signed main(void){
fastio;
int t;
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... |