# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
852183 | 2023-09-21T11:55:11 Z | c2zi6 | Palindromic Partitions (CEOI17_palindromic) | C++14 | 0 ms | 344 KB |
#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) { while (A.subst(l, r) != B.subst(n-r-1, n-l-1)) { r++; if (r == n) { cout << ans + 1 << endl; return; } } l = r = r+1; ans += 2; if (r == n) { cout << ans + n%2 << endl; return; } } } int main() { int t = 1; cin >> t; while (t--) solve(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |