Submission #300467

#TimeUsernameProblemLanguageResultExecution timeMemory
300467bacegen4oGuess the number (BOI20_guess)C11
100 / 100
1 ms416 KiB
#pragma GCC optimize "-O3"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<assert.h>
#include<stdbool.h>
#include<limits.h>

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);
    return 0;
}

Compilation message (stderr)

Guess.c: In function 'main':
Guess.c:12:5: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   12 |     scanf("%d", &N);
      |     ^~~~~~~~~~~~~~~
Guess.c:19:9: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
   19 |         scanf("%d", &fb);
      |         ^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...