# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199681 | rKrPaN | Palindromic Partitions (CEOI17_palindromic) | C++98 | 568 ms | 19148 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 <iostream>
#include <string>
using namespace std;
long long H[1000100];
long long pot[1000100];
long long h(int l, int d){
l++; d++;
return H[d] - H[l-1] * pot[d-l+1];
}
int main(){
int t;
cin >> t;
for (int ij = 0; ij < t; ij++){
string s;
cin >> s;
int n = s.size();
H[1] = s[0]-'a';
pot[1] = 37;
int p = 1;
for (int i = 2; i <= n; i++){
H[i] = 37*H[i-1] + s[i-1]-'a';
pot[i] = pot[i-1] * 37;
}
int sol = 1;
int d = 1, o = 0;
for (int i = 0; i < n/2; i++){
long long hl = h(o, o + d-1);
long long hd = h(n-o-d, n-o-1);
/*
cout << d << " " << o << "\n";
cout << sol << "\n";
cout << hl << " " << hd << "\n";
*/
if (hl == hd){
o += d;
d = 0;
sol+= 2;
}
d++;
}
if (n%2 == 0 && d == 1)sol--;
cout << sol << "\n";
}
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... |