# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
4076 | ainta | Make superpalindrome! (kriii1_M) | C++98 | 0 ms | 1284 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
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);
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);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |