답안 #545977

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
545977 2022-04-05T19:11:30 Z skittles1412 Colors (BOI20_colors) C++17
0 / 100
2 ms 592 KB
#include "bits/extc++.h"

using namespace std;

template <typename T>
void dbgh(const T& t) {
	cerr << t << endl;
}

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
	cerr << t << " | ";
	dbgh(u...);
}

#ifdef DEBUG
#define dbg(...)                                           \
	cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
		 << ": ";                                          \
	dbgh(__VA_ARGS__)
#else
#define cerr   \
	if (false) \
	cerr
#define dbg(...)
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())

// 0 = x > query
// 1 = x <= query

int n;

int search(int l, int r, bool add) {
	if (l == r) {
		if (add) {
			return 1;
		} else {
			return n;
		}
	}
	int mid = (l + r) / 2;
	int nxt = search(mid + 1, r, !add);
	if (add) {
		return nxt - mid;
	} else {
		return nxt + mid;
	}
}

void solve(int l, int r, int prev, bool add) {
	if (l == r) {
		cout << "= " << l << endl;
		return;
	}
	int mid = (l + r) / 2;
	if (add) {
		prev += mid;
	} else {
		prev -= mid;
	}
	cout << "? " << prev << endl;
	int ans;
	cin >> ans;
	if (ans) {
		solve(l, mid, prev, !add);
	} else {
		solve(mid + 1, r, prev, !add);
	}
}

void solve() {
	cin >> n;
	int start = search(1, n, true);
	dbg(start);
	cout << "? " << start << endl;
	int _;
	cin >> _;
	solve(1, n, start, true);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.exceptions(ios::failbit);
	solve();
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 592 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -