Cod sursa(job #3209422)

Utilizator matwudemagogul matwu Data 2 martie 2024 13:12:11
Problema Cbinteractiv Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.44 kb
#include <bits/stdc++.h>
using namespace std;

int n;
int main(){
    cin >> n;
    int l = 1, r = n;
    int ans = 0;
    while(l <= r){
        int tm = (l + r) / 2;
        cout << "? " << tm << '\n';
        cout.flush();
        int nr;
        cin >> nr;
        if(nr){
            ans = max(ans, tm);
            l = tm + 1;
        }else{
            r = tm - 1;
        }
    }
    cout << "! " << ans;
    cout.flush();
}