Submission #131016

# Submission time Handle Problem Language Result Execution time Memory
131016 2019-07-16T11:16:35 Z sebinkim Snake (CEOI08_snake) C++14
100 / 100
3 ms 376 KB
#include <bits/stdc++.h>

#include "snakelib.h"

using namespace std;

int main()
{
	int i, k, d, s1, s2, e1, e2, m1, m2;
	char a1, a2;
	
	k = get_speed();
	
	s1 = 0; e1 = 12121;
	s2 = 0; e2 = 12121;
	
	for(i=0; i<13; i++){
		e1 = min(12121, e1 + k);
		e2 = min(12121, e2 + k);
		
		if(max(s1, s2) <= min(e1, e2) - 3){
			s1 = s2 = min(s1, s2);
			e1 = e2 = max(e1, e2);
			m1 = (s1 * 2 + e1) / 3;
			m2 = (s1 + e1 * 2) / 3;
			
			ask_snake(m1, m2, &a1, &a2);
			
			if(a1 == 'b' && a2 == 'f'){
				s1 = s2 = m1 + 1;
				e1 = e2 = m2 - 1;
			}
			else if(a1 == 'f') e1 = e2 = m1 - 1;
			else if(a2 == 'b') s1 = s2 = m2 + 1;
			else{
				if(a1 == 's') e1 = m1;
				else s1 = m1 + 1, e1 = m2;
				if(a2 == 's') s2 = m2;
				else s2 = m1, e2 = m2 - 1;
			}
		}
		else{
			m1 = (s1 + e1) / 2;
			m2 = (s2 + e2) / 2;
			
			ask_snake(m1, m2, &a1, &a2);
			
			if(a1 == 'b') s1 = m1 + 1;
			else e1 = m1 - 1;
			
			if(a2 == 'f') e2 = m2 - 1;
			else s2 = m2 + 1;
		}
	}
	
	tell_length(e2 - e1);
}

Compilation message

snake.cpp: In function 'int main()':
snake.cpp:9:12: warning: unused variable 'd' [-Wunused-variable]
  int i, k, d, s1, s2, e1, e2, m1, m2;
            ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct: estimate ok. 13 calls needed
2 Correct 2 ms 376 KB Output is correct: estimate ok. 13 calls needed
3 Correct 2 ms 376 KB Output is correct: estimate ok. 13 calls needed
4 Correct 2 ms 248 KB Output is correct: estimate ok. 13 calls needed
5 Correct 2 ms 376 KB Output is correct: estimate ok. 13 calls needed
6 Correct 2 ms 248 KB Output is correct: estimate ok. 13 calls needed
7 Correct 2 ms 248 KB Output is correct: estimate ok. 13 calls needed
8 Correct 2 ms 248 KB Output is correct: estimate ok. 13 calls needed
9 Correct 1 ms 248 KB Output is correct: estimate ok. 13 calls needed
10 Correct 2 ms 296 KB Output is correct: estimate ok. 13 calls needed
11 Correct 3 ms 376 KB Output is correct: estimate ok. 13 calls needed
12 Correct 2 ms 248 KB Output is correct: estimate ok. 13 calls needed
13 Correct 2 ms 248 KB Output is correct: estimate ok. 13 calls needed
14 Correct 2 ms 376 KB Output is correct: estimate ok. 13 calls needed
15 Correct 2 ms 252 KB Output is correct: estimate ok. 13 calls needed
16 Correct 2 ms 248 KB Output is correct: estimate ok. 13 calls needed
17 Correct 2 ms 376 KB Output is correct: estimate ok. 13 calls needed
18 Correct 2 ms 248 KB Output is correct: estimate ok. 13 calls needed
19 Correct 2 ms 248 KB Output is correct: estimate ok. 13 calls needed
20 Correct 2 ms 376 KB Output is correct: estimate ok. 13 calls needed