# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
619708 | socpite | Palindromic Partitions (CEOI17_palindromic) | C++14 | 438 ms | 22740 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 f first
#define s second
typedef long long ll;
const int maxn = 1e6+5;
const int mod = 1e9+7;
int t, n, q;
string str, str2;
int d[2*maxn];
int man1[maxn], man2[maxn];
void pp(){
string tmp;
for(int i = n-1; i >= n/2 + (n&1); i--)tmp+=str[i];
str2 = tmp;
tmp = "";
for(int i = 0; i < n/2; i++)tmp+=str[i];
str = tmp;
tmp = "$#";
for(int i = 0; i < n/2; i++){
tmp+=str[i];
tmp+='#';
}
tmp+='^';
str = tmp;
tmp = "$#";
for(int i = n/2+(n&1); i < n; i++){
tmp+=str2[i-(n/2+(n&1))];
tmp+='#';
}
tmp += '^';
str2 = tmp;
//cout << str << " " << str2 << endl;
}
int main(){
cin >> t;
while(t--){
cin >> str;
n=str.size();
pp();
for(int i = 1, l =0,r = 0; i < str.size(); i++){
if(r < i)d[i]=0;
else d[i] = min(r-i, d[l+r-i]);
while(str[i+d[i]] == str2[i-d[i]] && str[i-d[i]] == str2[i+d[i]])d[i]++;
if(i+d[i] > r){
l = i-d[i], r = i+d[i];
}
if(i&1){
if(i > 1 && i < str.size()-2)man2[(i>>1)-1]=d[i]>>1;
}
else{
if(i && i < str.size()-1)man1[(i>>1)-1]=d[i]>>1;
}
}
int crr = 0, ans = 0;
for(int i = 0; i < n/2; i++){
if(man1[i]){
if(crr >= i-man1[i]+1 && crr <= i){
crr+=(i-crr)*2+1;
ans+=2;
}
}
//cout << man1[i] << endl;
if(man2[i] && i < n/2-1){
if(crr >= i-man2[i]+1 && crr <= i){
crr+=(i-crr+1)*2;
ans+=2;
}
}
//cout << man2[i] << endl;
}
if(crr < n/2 || (n&1))ans++;
cout << ans << "\n";
}
}
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... |