#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);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1284 KB |
Output is correct |
2 |
Correct |
0 ms |
1284 KB |
Output is correct |
3 |
Correct |
0 ms |
1284 KB |
Output is correct |
4 |
Correct |
0 ms |
1284 KB |
Output is correct |
5 |
Correct |
0 ms |
1284 KB |
Output is correct |
6 |
Correct |
0 ms |
1284 KB |
Output is correct |
7 |
Correct |
0 ms |
1284 KB |
Output is correct |
8 |
Correct |
0 ms |
1284 KB |
Output is correct |
9 |
Correct |
0 ms |
1284 KB |
Output is correct |
10 |
Correct |
0 ms |
1284 KB |
Output is correct |
11 |
Correct |
0 ms |
1284 KB |
Output is correct |
12 |
Incorrect |
0 ms |
1284 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |