Submission #13862

# Submission time Handle Problem Language Result Execution time Memory
13862 2015-04-08T10:30:35 Z baneling100 Make superpalindrome! (kriii1_M) C++
0 / 1
0 ms 1196 KB
#include <stdio.h>
#include <string.h>
#define L_MAX 100000

int L;
char S[L_MAX+1];

int makePalin(int left, int right) {

    int num, mid=(left+right)/2, k, t;

    if(left<right) {
        if((right-left)%2) {
            k=makePalin(left,mid);
            if(k) {
                strncpy(S+mid+1,S+left,mid-left+1);
                return 1;
            }
            else {
                num=strncmp(S+left,S+mid+1,mid-left+1);
                if(num>0) {
                    strncpy(S+mid+1,S+left,mid-left+1);
                    return 1;
                }
                else if(num<0) {
                    t=mid;
                    while(S[t]=='z') S[t--]='a';
                    S[t]++;
                    k=makePalin(left,mid);
                    strncpy(S+mid+1,S+left,mid-left+1);
                    return 1;
                }
                else return 0;
            }
        }
        else {
            k=makePalin(left,mid-1);
            if(k) {
                S[mid]='a';
                strncpy(S+mid+1,S+left,mid-left);
                return 1;
            }
            else {
                num=strncmp(S+left,S+mid+1,mid-left);
                if(num>0) {
                    strncpy(S+mid+1,S+left,mid-left);
                    return 1;
                }
                else if(num<0) {
                    if(S[mid]=='z') {
                        t=mid-1;
                        while(S[t]=='z') S[t--]='a';
                        S[t]++;
                        makePalin(left,mid-1);
                        S[mid]='a';
                        strncpy(S+mid+1,S+left,mid-left);
                    }
                    else {
                        S[mid]++;
                        strncpy(S+mid+1,S+left,mid-left);
                    }
                    return 1;
                }
                else return 0;
            }
        }
    }
}

int main(void) {

    int temp, t;

    scanf("%s",S);
    L=strlen(S);
    t=L-1;
    while(S[t]=='z') S[t--]='a';
    S[t]++;
    temp=makePalin(0,L-1);
    printf("%s",S);

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1196 KB Output is correct
2 Incorrect 0 ms 1196 KB Output isn't correct
3 Halted 0 ms 0 KB -