Submission #3815

#TimeUsernameProblemLanguageResultExecution timeMemory
3815QwazMake superpalindrome! (kriii1_M)C++98
1 / 1
0 ms1672 KiB
#include <cstdio> #include <algorithm> const int MAX=100020; char data[MAX]; int len; void calcLength(){ while(data[len]) len++; } int where[MAX]; void process(int s, int e){ if(s >= e) return; int m = (e+s)>>1; if((e-s)%2){ where[m] = e-s; process(s, m); process(m+1, e); } else { process(s, s+(e-s)/2); process(s+(e-s)/2, e); } } char min[MAX]; int pos; void solve(){ int i; for(i=0; i<len; i++){ if(min[where[i]] == 0){ min[where[i]] = data[i]; if(data[i] != 'z') pos = i; } else { if(min[where[i]] < data[i]) break; else if(min[where[i]] > data[i]){ pos = i; min[where[i]]--; break; } } } min[where[pos]]++; for(i=0; i<len; i++){ if(where[i]/2 > pos) putchar('a'); else putchar(min[where[i]]); } puts(""); } int main(){ scanf("%s", data); calcLength(); process(0, len); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...