답안 #719374

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
719374 2023-04-05T21:08:32 Z rainboy Snake (CEOI08_snake) C++17
100 / 100
1 ms 560 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct: estimate ok. 13 calls needed
2 Correct 0 ms 336 KB Output is correct: estimate ok. 13 calls needed
3 Correct 1 ms 336 KB Output is correct: estimate ok. 13 calls needed
4 Correct 0 ms 336 KB Output is correct: estimate ok. 13 calls needed
5 Correct 1 ms 508 KB Output is correct: estimate ok. 13 calls needed
6 Correct 1 ms 336 KB Output is correct: estimate ok. 13 calls needed
7 Correct 1 ms 336 KB Output is correct: estimate ok. 13 calls needed
8 Correct 1 ms 336 KB Output is correct: estimate ok. 13 calls needed
9 Correct 1 ms 336 KB Output is correct: estimate ok. 13 calls needed
10 Correct 1 ms 336 KB Output is correct: estimate ok. 13 calls needed
11 Correct 1 ms 336 KB Output is correct: estimate ok. 11 calls needed
12 Correct 0 ms 336 KB Output is correct: estimate ok. 13 calls needed
13 Correct 1 ms 336 KB Output is correct: estimate ok. 10 calls needed
14 Correct 1 ms 560 KB Output is correct: estimate ok. 13 calls needed
15 Correct 1 ms 336 KB Output is correct: estimate ok. 13 calls needed
16 Correct 1 ms 336 KB Output is correct: estimate ok. 13 calls needed
17 Correct 1 ms 336 KB Output is correct: estimate ok. 13 calls needed
18 Correct 0 ms 336 KB Output is correct: estimate ok. 13 calls needed
19 Correct 1 ms 336 KB Output is correct: estimate ok. 13 calls needed
20 Correct 1 ms 336 KB Output is correct: estimate ok. 13 calls needed