# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
3815 | Qwaz | Make superpalindrome! (kriii1_M) | C++98 | 0 ms | 1672 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |