# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
852191 | c2zi6 | Palindromic Partitions (CEOI17_palindromic) | C++14 | 0 ms | 348 KiB |
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;
using ll = long long;
using ld = long double;
vector<ll> Bpow;
ll B = 31;
ll P = 1e9 + 9;
struct HASHED {
vector<ll> pref;
HASHED(string s) {
if (Bpow.empty()) Bpow.push_back(1);
while (Bpow.size() <= s.size()) Bpow.push_back(Bpow.back() * B % P);
pref = vector<ll>(s.size()+1);
pref[0] = 0;
for (int i = 1; i <= s.size(); i++) {
pref[i] = pref[i-1] * B + (s[i-1] - 'a' + 1) % P;
}
}
ll subst(ll l, ll r) {
ll a = pref[l] * Bpow[r-l+1] % P;
ll b = pref[r+1];
return (b + P - a) % P;
}
};
void solve() {
string s;
cin >> s;
int n = s.size()/2;
string a, b;
for (int i = 0; i < n; i++) {
a.push_back(s[i]);
b.push_back(s[i+n+s.size()%2]);
}
HASHED A(a), B(b);
int l = 0, r = 0;
int ans = 0;
while (true) {
if (r == n) {
cout << ans + s.size()%2 << endl;
return;
}
while (A.subst(l, r) != B.subst(n-r-1, n-l-1)) {
r++;
if (r == n) {
cout << ans + 1 << endl;
return;
}
}
l = r+1;
r = r+1;
ans += 2;
}
}
int main() {
int t = 1;
cin >> t;
while (t--) solve();
}
Compilation message (stderr)
# | 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... |