Cod sursa(job #2961943)

Utilizator Dragono63Stanciu Rares Stefan Dragono63 Data 7 ianuarie 2023 14:16:57
Problema Cbinteractiv Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.21 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;
int s, p;
/*******************************/
/// FUNCTIONS

void ReadInput();
void Solution();
void Output();
/*******************************/
///-------------------------------------
inline void ReadInput()
{
    cin >> N;
}
///-------------------------------------
bool check(ci &x)
{
    if (x > N) return false;
    short bit;
    cout << "? " << x << "\n";
    cin >> bit;
    cout.flush();
    return (bit == 1);
}
///-------------------------------------
inline void Solution()
{
    s = 0, p = (1 << (int(log2(N)) + 1));

    while (p)
    {
        if (check(s + p)) 
            s += p;
        
        p >>= 1;
    }
}
///-------------------------------------
inline void Output()
{
    cout  << "! " << s << "\n";
    cout.flush();
    exit(0);
}
///-------------------------------------
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ReadInput();
    Solution();
    Output();
    return 0;
}