# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
869247 | LOLOLO | Palindromic Partitions (CEOI17_palindromic) | C++14 | 67 ms | 28440 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;
const int N = 1e6 + 5;
const int BASE = 37;
long long haha[N];
long long hihi[N];
long long kkk(int L, int R)
{
return haha[R] - haha[L - 1] * hihi[R - L + 1];
}
void solve()
{
string s;
cin >> s;
int n = s.size();
s = ' ' + s;
for (int i = 1; i <= n; i++)
haha[i] = haha[i - 1] * BASE + s[i] - 'a' + 1;
int l = 1, r = n;
int ahihi = 1, orz = n;
long long hjhj, hehe;
int ans = 0;
while (l < r)
{
hjhj = kkk(ahihi, l);
hehe = kkk(r, orz);
if (hjhj == hehe)
{
ahihi = l + 1,
orz = r - 1;
ans += 2;
hjhj = 0, hehe = 0;
}
l++;
r--;
}
cout << ans + (l == r || hjhj != hehe) << "\n";
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
hihi[0] = 1;
for (int i = 1; i < N; i++)
hihi[i] = hihi[i - 1] * BASE;
int t;
cin >> t;
while (t--)
solve();
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... |