Submission #598809

#TimeUsernameProblemLanguageResultExecution timeMemory
598809MilosMilutinovicGuess the number (BOI20_guess)C++14
100 / 100
1 ms316 KiB
/**
 *    author:  wxhtzdy
 *    created: 19.07.2022 07:53:20
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n;
  cin >> n;
  auto Ask = [&](int x) {
    cout << "? " << x << endl;
    cin >> x;
    return x;
  };
  int low = 1, high = n;
  while (low <= high) {
    int mid = low + high >> 1;
    int x = Ask(mid);
    if (x == 0) {
      cout << "= " << mid << endl;
      return 0;
    }
    if (x == -1) {
      low = mid + 1;
    } else {
      high = mid - 1;
    }
  }                                                         
  return 0;
}

Compilation message (stderr)

Guess.cpp: In function 'int main()':
Guess.cpp:21:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |     int mid = low + high >> 1;
      |               ~~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...