제출 #636504

#제출 시각아이디문제언어결과실행 시간메모리
636504tvladm2009Guess the number (BOI20_guess)C++14
100 / 100
1 ms256 KiB
#include <iostream> using namespace std; int n, res = 0; void ask(int x) { cout << "? " << x << "\n"; cout.flush(); cin >> res; } int cb() { int l = 1, r = n, sol = -1; while (l <= r) { int mid = (l + r) / 2; ask(mid); if (res == 0) { sol = mid; break; } else if (res == 1) { r = mid - 1; } else { l = mid + 1; } } return sol; } int main() { cin >> n; int answer = cb(); cout << "= " << answer; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...