# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
320682 | phathnv | Palindromic Partitions (CEOI17_palindromic) | C++11 | 57 ms | 15076 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 mp make_pair
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef pair <int, int> ii;
const int N = 1e6 + 1;
const int base = 163;
int t, n;
char s[N];
ll pw[N];
void prepare(){
pw[0] = 1;
for(int i = 1; i < N; i++)
pw[i] = pw[i - 1] * base;
}
void readInput(){
scanf("%s", s + 1);
n = strlen(s + 1);
}
void solve(){
int res = 0;
int l = 1, r = n, len = 0;
ll hashedL = 0, hashedR = 0;
while (l < r){
hashedL = hashedL * base + s[l++];
hashedR = hashedR + s[r--] * pw[len++];
if (hashedL == hashedR){
hashedL = hashedR = 0;
res += 2;
len = 0;
}
}
if (hashedL || l <= r)
res++;
printf("%d\n", res);
}
int main(){
scanf("%d", &t);
prepare();
while (t--){
readInput();
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... |