답안 #3747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
3747 2013-08-31T08:05:24 Z jihoon Make superpalindrome! (kriii1_M) C++
0 / 1
0 ms 1672 KB
#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);
    }

}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 1672 KB Output isn't correct
2 Halted 0 ms 0 KB -