Cod sursa(job #2961949)

Utilizator Dragono63Stanciu Rares Stefan Dragono63 Data 7 ianuarie 2023 14:30:41
Problema Cbinteractiv Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.2 kb
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
using ll = long long;
using ci = const int;
using cll = const long long;

using namespace std;

/*******************************/
// INPUT / OUTPUT

/*******************************/
/// GLOBAL DECLARATIONS

int N;
/*******************************/
/// FUNCTIONS

void ReadInput();
void Solution();
/*******************************/
///-------------------------------------
inline void ReadInput()
{
    cin >> N;
}
///-------------------------------------
inline void Solution()
{
    int st = 1, dr = N;

    int bit, mid;
    while (st <= dr)
    {
        mid = (st + dr) / 2;
        cout << "? " << mid << "\n";
        cout.flush();

        cin >> bit;
        if (bit == -1) exit(0);
        if (bit == 0)
        {
            st = mid + 1;
        }
        else
        {
            dr = mid;
            if (st == dr)
            {
                cout << "! " << mid << "\n";
                cout.flush();
                exit(0); 
            }
        }
    }
}
///-------------------------------------
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ReadInput();
    Solution();
    return 0;
}