답안 #3722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
3722 2013-08-31T07:51:24 Z Qwaz Make superpalindrome! (kriii1_M) C++
0 / 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 = where[i];
		} else {
			if(min[where[i]] < data[i])
				break;
			else if(min[where[i]] > data[i]){
				pos = where[i];
				min[where[i]]--;
				break;
			}
		}
	}

	min[pos]++;

	for(i=0; i<len; i++){
		if(where[i] > pos)
			putchar('a');
		else
			putchar(min[where[i]]);
	}

	puts("");
}

int main(){
	scanf("%s", data);

	calcLength();
	process(0, len);
	solve();

	return 0;
}
# 결과 실행 시간 메모리 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 Incorrect 0 ms 1672 KB Output isn't correct
7 Halted 0 ms 0 KB -