# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
162251 | karma | Palindromic Partitions (CEOI17_palindromic) | C++14 | 18 ms | 10308 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>
#define pb emplace_back
#define ll long long
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int N = int(2e5) + 7;
const int mod = int(1e9) + 9;
const ll sqrMod = 1ll * mod * mod;
const ll Base = 33;
typedef pair<int, int> pii;
ll Hash[N], p[N];
string s;
int n;
int GetHash(int l, int r) {return (Hash[r] - Hash[l - 1] * p[r - l + 1] + sqrMod) % mod;}
void Solve() {
cin >> s; s = ' ' + s;
n = int(s.size()) - 1;
for(int i = 1; i <= n; ++i) Hash[i] = (Hash[i - 1] * Base + s[i] - 'a') % mod;
int i = 1, j = n, len = 1, res = 0;
while(i <= j) {
if(GetHash(i, i + len - 1) == GetHash(j - len + 1, j)) {
if(i + len - 1 < j - len + 1) res += 2;
else ++res;
//cout << i << ' ' << j << ' ' << len << '\n';
i = i + len; j = j - len; len = 1;
} else ++len;
}
cout << res << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define Task "test"
if(fopen(Task".inp", "r")) {
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
}
p[0] = 1;
for(int i = 1; i < N; ++i) p[i] = p[i - 1] * Base % mod;
int nTest; cin >> nTest;
while(nTest --) 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... |