답안 #575464

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
575464 2022-06-10T16:03:08 Z _karan_gandhi Colors (BOI20_colors) C++17
0 / 100
1 ms 208 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define all(v) v.begin(), v.end()
#define endl '\n'
#define pl(var) " [" << #var << ": " << (var) << "] "

template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "[" << p.first << ", " << p.second << "]"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) { cout << "["; for(int i = 0; i < (int)v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";}

ll int n;;

bool query(ll int diff, ll int prev) {

	if (prev + diff > n) {
		cout << "? 1" << endl;
		cout.flush();
		int s; cin >> s;
		prev = 1;
	}
	assert(prev + diff <= n);
	cout << "? " << prev + diff << endl;
	cout.flush();
	int s; cin >> s;
	return (bool)s;
}

void solve() {
	cin >> n;

	int prev = 1;
	query(1, 0);

	ll int hi = n - 1;
	ll int lo = 1;
	ll int ans = n;

	while (hi >= lo) {
		int mid = (hi + lo) / 2;

		if (query(mid, prev)) {
			ans = mid;
			hi = mid - 1;
		} else {
			lo = mid + 1;
		}
		prev = mid;
	}

	cout << "= " << ans << endl;
	cout.flush();
}

int main() {
	// ios::sync_with_stdio(false);
	// cin.tie(nullptr);

	int T = 1;
	// cin >> T;
	while (T--) 
		solve();

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB Hair color 1 was used multiple times
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB Hair color 1 was used multiple times
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB Hair color 1 was used multiple times
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB Hair color 1 was used multiple times
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 208 KB Hair color 1 was used multiple times
2 Halted 0 ms 0 KB -