#include<stdio.h>
#include<string.h>
int len;
int str[100000]={0};
char s[100001]={0};
char ans[100001]={0};
void f(int a,int b){
if(a==b) return;
int i;
f(a,(a+b-1)/2);
for(i=b;i>(a+b)/2;i--){
str[i]=str[b-i+a];
}
}
int main()
{
int i,ch=0;
scanf("%s",&s);
len=strlen(s);
for(i=0;i<len;i++) str[i]=i;
f(0,len-1);
for(i=0;i<len;i++){
if(i==str[i]) ans[i]=s[i];
}
for(i=0;i<len;i++){
if(ans[str[i]]!=s[i]){
ch=1;
break;
}
}
if(ch==0){
for(i=len-1;i>=0;i--){
if(i==str[i] && ans[str[i]]!='z'){
ans[str[i]]++;
for(i++;i<len;i++)
if(i==str[i]) ans[i]='a';
break;
}
}
}
else{
for(i=0;i<len;i++){
if(ans[str[i]]<s[i]){
for(;i>=0;i--){
if(i==str[i] && ans[str[i]]!='z'){
ans[str[i]]++;
break;
}
}
for(i++;i<len;i++){
if(i==str[i])
ans[str[i]]='a';
}
break;
}
else if(ans[str[i]]>s[i]){
for(i++;i<len;i++){
if(i==str[i])
ans[str[i]]='a';
}
}
}
}
for(i=0;i<len;i++) printf("%c",ans[str[i]]);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1672 KB |
Output is correct |
2 |
Correct |
0 ms |
1672 KB |
Output is correct |
3 |
Correct |
0 ms |
1672 KB |
Output is correct |
4 |
Correct |
0 ms |
1672 KB |
Output is correct |
5 |
Correct |
0 ms |
1672 KB |
Output is correct |
6 |
Correct |
0 ms |
1672 KB |
Output is correct |
7 |
Correct |
0 ms |
1672 KB |
Output is correct |
8 |
Correct |
0 ms |
1672 KB |
Output is correct |
9 |
Correct |
0 ms |
1672 KB |
Output is correct |
10 |
Correct |
0 ms |
1672 KB |
Output is correct |
11 |
Correct |
0 ms |
1672 KB |
Output is correct |
12 |
Correct |
0 ms |
1672 KB |
Output is correct |
13 |
Correct |
0 ms |
1672 KB |
Output is correct |
14 |
Correct |
0 ms |
1672 KB |
Output is correct |
15 |
Correct |
0 ms |
1672 KB |
Output is correct |
16 |
Correct |
0 ms |
1672 KB |
Output is correct |
17 |
Correct |
0 ms |
1672 KB |
Output is correct |
18 |
Correct |
0 ms |
1672 KB |
Output is correct |
19 |
Correct |
0 ms |
1672 KB |
Output is correct |
20 |
Correct |
0 ms |
1672 KB |
Output is correct |