답안 #299562

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
299562 2020-09-15T08:01:21 Z E869120 Colors (BOI20_colors) C++14
0 / 100
1 ms 256 KB
#include <bits/stdc++.h>
using namespace std;

int Debug = 1;
long long N;
long long C = 1;
long long prevs = 0;

int getans(long long pos) {
	cout << "? " << pos << endl;
	if (Debug == 1) {
		int x;
		cin >> x;
		return x;
	}
	if (Debug == 2) {
		int x = -1;
		if (abs(prevs - pos) < C) x = 0;
		else x = 1;
		prevs = pos;
		return x;
	}
	return -1;
}

int main() {
	// Step #1. Input
	cin >> N;
	if (N == 1) {
		cout << "= 1" << endl;
		return 0;
	}
	
	// Step #2. Get Answer
	long long cl = 1, cr = (N / 2) + 1, cm, minx = N;
	long long precm = -1, pre = -1;
	for (int i = 0; i < 100; i++) {
		cm = (cl + cr) / 2; if (precm == cm) break;
		precm = cm;
		int z1 = getans(cm);
		if (pre != -1LL && z1 == 1) minx = min(minx, abs(pre - cm));
		pre = cm;
		int z2 = getans(N + 1LL - cm);
		if (pre != -1LL && z2 == 1) minx = min(minx, abs(pre - (N + 1LL - cm)));
		pre = N + 1LL - cm;
		if (z2 == 1) { cl = cm; }
		else { cr = cm; }
	}
	
	// Step #3. Baaiwake
	if (N % 2LL == 1LL) {
		int z3 = getans(N / 2LL + 1LL);
		if (pre != -1LL && z3 == 1) minx = min(minx, abs(pre - (N / 2LL + 1LL)));
	}
	
	// Step #4. Get Answer
	cout << "= " << minx << endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 256 KB Hair color 2 was used multiple times
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 256 KB Hair color 2 was used multiple times
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 256 KB Hair color 2 was used multiple times
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 256 KB Hair color 2 was used multiple times
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 256 KB Hair color 2 was used multiple times
2 Halted 0 ms 0 KB -