Submission #774979

#TimeUsernameProblemLanguageResultExecution timeMemory
774979hgmhcGuess the number (BOI20_guess)C++17
100 / 100
1 ms292 KiB
#include <bits/stdc++.h> using namespace std; bool f(int x) { printf("? %d\n", x); fflush(stdout); int q; scanf("%d", &q); if (q == 0) { printf("= %d\n", x); fflush(stdout); exit(0); } else if (q < 0) return true; else return false; } int main() { int n; scanf("%d", &n); int a = 1, b = n; while (a <= b) { int m = (a+b)/2; if (f(m)) a = m+1; else b = m-1; } }

Compilation message (stderr)

Guess.cpp: In function 'bool f(int)':
Guess.cpp:7:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     int q; scanf("%d", &q);
      |            ~~~~~^~~~~~~~~~
Guess.cpp: In function 'int main()':
Guess.cpp:18:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     int n; scanf("%d", &n);
      |            ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...