# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
545826 | Ai7081 | Palindromic Partitions (CEOI17_palindromic) | C++17 | 53 ms | 15056 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;
#define long long long
const long mod = 1e9+7;
const long key = 31;
long t, out, l, r, now, po[500005];
string s;
stack<char> st;
bool ok;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
po[0] = 1;
for (long i=1; i<=500000; i++) po[i] = (po[i-1] * key) % mod;
cin >> t;
while (t--) {
cin >> s;
ok = false;
out = l = r = now = 0;
for (long i=0; i<s.size()/2; i++) {
l *= key, l += (s[i]-'a'), l %= mod;
r += (s[s.size()-1-i]-'a')*po[now], r %= mod;
if (l == r) now = l = r = 0, out += 2;
else now++;
}
(s.size()%2 || now) ? cout << out+1 << endl : cout << out << endl;
}
return 0;
}
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... |