Submission #4075

#TimeUsernameProblemLanguageResultExecution timeMemory
4075aintaMake superpalindrome! (kriii1_M)C++98
0 / 1
0 ms1284 KiB
#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 timeMemoryGrader output
Fetching results...