Submission #3815

# Submission time Handle Problem Language Result Execution time Memory
3815 2013-08-31T08:30:21 Z Qwaz Make superpalindrome! (kriii1_M) C++
1 / 1
0 ms 1672 KB
#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
1 Correct 0 ms 1672 KB Output is correct
2 Correct 0 ms 1672 KB Output is correct
3 Correct 0 ms 1672 KB Output is correct
4 Correct 0 ms 1672 KB Output is correct
5 Correct 0 ms 1672 KB Output is correct
6 Correct 0 ms 1672 KB Output is correct
7 Correct 0 ms 1672 KB Output is correct
8 Correct 0 ms 1672 KB Output is correct
9 Correct 0 ms 1672 KB Output is correct
10 Correct 0 ms 1672 KB Output is correct
11 Correct 0 ms 1672 KB Output is correct
12 Correct 0 ms 1672 KB Output is correct
13 Correct 0 ms 1672 KB Output is correct
14 Correct 0 ms 1672 KB Output is correct
15 Correct 0 ms 1672 KB Output is correct
16 Correct 0 ms 1672 KB Output is correct
17 Correct 0 ms 1672 KB Output is correct
18 Correct 0 ms 1672 KB Output is correct
19 Correct 0 ms 1672 KB Output is correct
20 Correct 0 ms 1672 KB Output is correct