Submission #13861

# Submission time Handle Problem Language Result Execution time Memory
13861 2015-04-08T08:15:36 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 divideConquer(int left, int right) {

    int ll=left, lm, lr, rl, rr=right, num, lt=0, rt=0;

    if((right-left)%2) {
        lr=(left+right)/2;
        rl=lr+1;
    }
    else {
        lr=(left+right)/2-1;
        rl=lr+2;
    }
    if(ll<lr) {
        lt=divideConquer(ll,lr);
        rt=divideConquer(rl,rr);
    }
    num=strncmp(S+ll,S+rl,lr-ll+1);
    if(num<0 && !lt) {
        lm=(ll+lr)/2;
        while(S[lm]=='z') {
            S[lm]=S[ll+lr-lm]='a';
            lm--;
        }
        S[lm]++;
        if(lm!=ll+lr-lm)
            S[ll+lr-lm]++;
    }
    strncpy(S+rl,S+ll,lr-ll+1);
    return lt||rt||num;
}

int main(void) {

    int temp;

    scanf("%s",S);
    L=strlen(S);
    temp=divideConquer(0,L-1);
    printf("%s",S);

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