Submission #16468

#TimeUsernameProblemLanguageResultExecution timeMemory
16468jihoonMake superpalindrome! (kriii1_M)C++98
0 / 1
0 ms2448 KiB
#include<cstdio> #include<string.h> char str[100005]; int n; int same[100002]; int core[100002]; int bunho[100002]; char lst[100002]; bool onlyz=true; int main(){ int ee,cnt=0,cnt2=0,i; scanf("%s",str); n=(int)strlen(str); for(i=0;i<n;i++){ onlyz=onlyz & (str[i]=='z'); } if(onlyz){ for(i=0;i<=n;i++){ printf("a"); } }else{ ee=n-1; str[ee]++; while(str[ee]==('z'+1)){ str[ee]='a'; ee--; str[ee]++; } ee=n-1; while(1){ for(i=ee/2+1;i<=ee;i++){ same[i]=ee-i; } if((ee+1)%2){ core[ee/2]=1; if(ee==0) break; ee--; } ee/=2; } for(i=0;i<n;i++){ if(core[i]){ ++cnt; bunho[i]=cnt; lst[cnt]=str[i]; }else{ bunho[i]=bunho[same[i]]; } } cnt2=0; for(i=0;i<n;i++){ if(core[i]){ cnt2++; }else{ if(lst[bunho[i]]<str[i]){ for(i=cnt2+1;i<=cnt;i++){ lst[i]='a'; } lst[cnt2]++; while(lst[cnt2]==('z'+1)){ lst[cnt2]='a'; cnt2--; lst[cnt2]++; } break; } } } for(i=0;i<n;i++){ printf("%c",lst[bunho[i]]); } } }
#Verdict Execution timeMemoryGrader output
Fetching results...