제출 #544792

#제출 시각아이디문제언어결과실행 시간메모리
544792rainboySnake (CEOI08_snake)C11
100 / 100
1 ms336 KiB
#include <stdio.h>
#include "snakelib.h"
 
#define N	12122
 
int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }
 
int main() {
	int k, llower, lupper, rlower, rupper, l, r;
	char c1, c2;
 
	k = get_speed();
	llower = 0, lupper = N - 1, rlower = 0, rupper = N - 1;
	l = (N - 1) / 3, r = (N - 1) * 2 / 3;
	ask_snake(l, r, &c1, &c2);
	if (c1 == 'b')
		llower = max(llower, l + 1), rlower = max(rlower, l + 1);
	else if (c1 == 'f')
		lupper = min(lupper, l - 1), rupper = min(rupper, l - 1);
	else
		lupper = min(lupper, l), rlower = max(rlower, l);
	if (c2 == 'b')
		llower = max(llower, r + 1), rlower = max(rlower, r + 1);
	else if (c2 == 'f')
		lupper = min(lupper, r - 1), rupper = min(rupper, r - 1);
	else
		lupper = min(lupper, r), rlower = max(rlower, r);
	while ((rupper - llower + 1) - max(rlower - lupper + 1, 1) > k * 2) {
		lupper = min(lupper + k, N);
		rupper = min(rupper + k, N);
		l = (llower + lupper) / 2, r = min((rlower + rupper) / 2 + 1, N - 1);
		ask_snake(l, r, &c1, &c2);
		if (c1 == 'b')
			llower = l + 1;
		else
			lupper = l;
		if (c2 == 'f')
			rupper = r - 1;
		else
			rlower = r;
	}
	tell_length(max(rlower - lupper + 1, 1) + k);
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...