#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]-1]<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 time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
2448 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |