# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1197800 | nvc2k8 | Colors (BOI20_colors) | C++20 | 0 ms | 436 KiB |
#include <bits/stdc++.h>
#define TASK "colors"
#define INT_LIM (int) 2147483647
#define LL_LIM (long long) 9223372036854775807
#define endl '\n'
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define BIT(i,x) (((i)>>(x))&1)
#define FOR(i,a,b) for(int i = (a); i<=(b); i++)
#define FORD(i,a,b) for(int i = (a); i>=(b); i--)
#define ll long long
#define pii pair<int,int>
using namespace std;
///------------------------------------------///
ll n;
#define ask(x) cout << "? " << (x) << endl; cout.flush();
#define answer(x) cout << "= " << (x) << endl; cout.flush();
void inp()
{
cin >> n;
}
ll ret = 0, lb = 0, rb = LL_LIM;
int querycnt = 0;
set<ll> dd;
void solve()
{
int response;
ll la = n-(1LL<<__lg(n));
ask(la); querycnt++; dd.insert(la);
cin >> response;
ll dir = 1;
FORD(pos, 59, 0)
{
ll delta = ret+(1LL<<pos);
if (delta>=n || delta<1) continue;
if (la+dir*delta>n || la+dir*delta<1) dir = -dir;
ll nw = la+dir*delta;
// cout << delta-2068728389572138 << endl; cout.flush();
if (dd.count(nw)) assert(false);
ask(nw); querycnt++; dd.insert(nw);
la = nw;
cin >> response;
if (response==0)
{
ret+= (1LL<<pos);
lb = max(lb, delta);
}
else
{
rb = min(rb, delta);
}
}
if (querycnt>64) assert(false);
answer(ret+1);
}
signed main()
{
///--------------------------///
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
if (fopen(TASK".INP","r")!=NULL)
{
freopen(TASK".INP","r",stdin);
freopen(TASK".OUT","w",stdout);
}
///--------------------------///
int NTEST = 1;
//cin >> NTEST;
while (NTEST--)
{
inp();
solve();
}
return 0;
}
///------------------------------------------///
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |