Submission #3747

#TimeUsernameProblemLanguageResultExecution timeMemory
3747jihoonMake superpalindrome! (kriii1_M)C++98
0 / 1
0 ms1672 KiB
#include<stdio.h> #include<string.h> char str[100003]={0}; char sv[100003]={0}; int len; int seq[50001][2]={0}; int seqp=0; int bs(int s,int e){ int i; int mid=(s+e)/2; if(s>e) return 0; if((e-s)%2==0){ seqp++; seq[seqp][0]=str[mid]; sv[mid]=str[mid]; seq[seqp][1]=mid; // printf("%c\n",str[mid]); } bs(s,mid-1+((e-s)%2)); for(i=s;i<=mid;i++){ sv[s+e-i]=sv[i]; } //printf("%s\n",sv); return 0; } int main(){ int i; bool dd=false; int svv; scanf("%s",str); len=(int)strlen(str); bs(0,len-1); svv=len-1; /* for(i=0;i<len;i++){ printf("%c",sv[i]); } printf("\n"); */ for(i=0;i<len;i++){ if(str[i]>sv[i]){ svv=i; break; }else if(str[i]<sv[i]){ dd=true; break; } } if(dd){ printf("%s",sv); }else{ for(i=1;i<=seqp;i++){ seq[i][0]-=97; } for(i=1;i<=seqp;i++){ if(seq[i][1]<=svv){ seq[i][0]++; // printf("%d\n",i); break; } } for(i=1;i<=seqp;i++){ seq[i+1][0]+=(seq[i][0]/26); seq[i][0]=seq[i][0]%26; } for(i=1;i<=seqp;i++){ seq[i][0]+=97; str[seq[i][1]]=seq[i][0]; } // printf("%s\n",str); bs(0,len-1); printf("%s",sv); } }
#Verdict Execution timeMemoryGrader output
Fetching results...