# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
4075 | ainta | Make superpalindrome! (kriii1_M) | C++98 | 0 ms | 1284 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<stdio.h>
#include<string.h>
char p[100010],pp[100010];
int n;
bool Next_Super(int a,int b){
if(a==b)return true;
int m=(a+b)>>1,i;
bool chk;
if(a%2==b%2){
chk=Next_Super(a,m-1);
Next_Super(m+1,b);
if(!chk){
for(i=m+1;i<=b;i++)p[i]=p[a+b-i];
p[m]='a';
return false;
}
else{
for(i=m+1;i<=b;i++){
if(p[i]>p[a+b-i]){
chk=false;
break;
}
if(p[i]!=p[a+b-i])break;
}
if(i==b+1)return true;
if(!chk){
if(p[m]!='z')p[m]++;
else{
p[m-1]++;
Next_Super(a,m-1);
p[m]='a';
}
}
for(i=m+1;i<=b;i++)p[i]=p[a+b-i];
return false;
}
}
else{
chk=Next_Super(a,m);
Next_Super(m+1,b);
if(!chk){
for(i=m+1;i<=b;i++)p[i]=p[a+b-i];
return false;
}
else{
for(i=m+1;i<=b;i++){
if(p[i]>p[a+b-i]){
chk=false;
break;
}
if(p[i]!=p[a+b-i])break;
}
if(i==b+1)return true;
if(!chk){
p[m]++;
Next_Super(a,m);
}
for(i=m+1;i<=b;i++)p[i]=p[a+b-i];
return false;
}
}
}
int main()
{
int i;
scanf("%s",p);
n=strlen(p);
for(i=0;i<n;i++)pp[i]=p[i];
Next_Super(0,n-1);
printf("%s\n",p);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |