Submission #254762

#TimeUsernameProblemLanguageResultExecution timeMemory
254762model_codeGuess the number (BOI20_guess)C++14
100 / 100
1 ms288 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int N;
    scanf("%d", &N);

    int L = 1;
    int R = N;

    while (L < R)
    {
        int mid = (L + R) / 2;
        printf("? %d\n", mid);
        fflush(stdout);

        int fb;
        scanf("%d", &fb);
        if (fb == 0)
        {
            L = R = mid;
            break;
        }
        else if (fb < 0)
        {
            L = mid + 1;
        }
        else
        {
            R = mid - 1;
        }
    }

    printf("= %d\n", L);
}

Compilation message (stderr)

Guess.cpp: In function 'int main()':
Guess.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
Guess.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &fb);
         ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...