답안 #130769

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
130769 2019-07-16T04:51:15 Z 임유진(#3171) Snake (CEOI08_snake) C++14
100 / 100
2 ms 376 KB
#include <stdio.h>
#include <algorithm>
#include "snakelib.h"

using namespace std;

int main() {
	const int hd = 12122;
	int K = get_speed();
	char A1, A2;
	int as = 0, ae = hd - 1, bs = 1, be = hd, ls = 1, le = hd;

	while(le - ls > 2 * K) {
		if(ae < bs) {
			int am = (as + ae) / 2, bm = (bs + be) / 2;
			ask_snake(am, bm, &A1, &A2);
			if(A1 == 's') {
				ae = am;
				be = min(be, ae + le);
			}
			else {
				as = am + 1;
				bs = max(bs, as + ls);
			}
			if(A2 == 's') {
				bs = bm + 1;
				as = max(as, bs - le);
			}
			else {
				be = bm;
				ae = min(ae, be - ls);
			}
		}
		else {
			int am = (2 * as + be) / 3, bm = (as + 2 * be) / 3;
			ask_snake(am, bm, &A1, &A2);

			if(A1 == 'f') be = min(be, am);
			else if(A1 == 's') {
				ae = min(ae, am);
				bs = max(bs, am + 1);
			}
			else as = am + 1;
			if(A2 == 'f') be = min(be, bm);
			else if(A2 == 's') {
				ae = min(ae, bm);
				bs = max(bs, bm + 1);
			}
			else as = bm + 1;

			as = max(as, bs - le);
			ae = min(ae, be - ls);
			bs = max(bs, as + ls);
			be = min(be, ae + le);
		}
		ls = max(ls, bs - ae);
		le = min(le, be - as);
		be = min(be + K, hd);
		ae = min(ae + K, be - ls);
	}
	
	tell_length((ls + le) / 2);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct: estimate ok. 13 calls needed
2 Correct 2 ms 248 KB Output is correct: estimate ok. 13 calls needed
3 Correct 2 ms 376 KB Output is correct: estimate ok. 12 calls needed
4 Correct 2 ms 248 KB Output is correct: estimate ok. 11 calls needed
5 Correct 2 ms 248 KB Output is correct: estimate ok. 12 calls needed
6 Correct 2 ms 252 KB Output is correct: estimate ok. 13 calls needed
7 Correct 2 ms 248 KB Output is correct: estimate ok. 10 calls needed
8 Correct 2 ms 252 KB Output is correct: estimate ok. 10 calls needed
9 Correct 2 ms 248 KB Output is correct: estimate ok. 10 calls needed
10 Correct 2 ms 248 KB Output is correct: estimate ok. 9 calls needed
11 Correct 2 ms 248 KB Output is correct: estimate ok. 9 calls needed
12 Correct 2 ms 376 KB Output is correct: estimate ok. 13 calls needed
13 Correct 2 ms 248 KB Output is correct: estimate ok. 7 calls needed
14 Correct 2 ms 376 KB Output is correct: estimate ok. 13 calls needed
15 Correct 2 ms 248 KB Output is correct: estimate ok. 12 calls needed
16 Correct 2 ms 248 KB Output is correct: estimate ok. 13 calls needed
17 Correct 2 ms 248 KB Output is correct: estimate ok. 13 calls needed
18 Correct 2 ms 248 KB Output is correct: estimate ok. 12 calls needed
19 Correct 2 ms 376 KB Output is correct: estimate ok. 11 calls needed
20 Correct 2 ms 248 KB Output is correct: estimate ok. 12 calls needed