This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
//ll last = 0, c;
bool query(ll x) // vrati true ak C >= |x - last|
{
cout << "? " << x << endl;
int i; cin >> i;
return i;
/*ll dif = abs(x-last); last = x;
cout << (c <= dif) << endl;
return c <= dif;*/
}
int main()
{
//ios::sync_with_stdio(false);
//cin.tie(0);
ll n;
cin >> n;
//cin >> c;
// najprv urobime fiktivne binarne vyhladavanie aby sme nasli dobru startovaciu poziciu
ll lo = 1, hi = n, pos = -1, d = 1, s = pos;
while (lo < hi)
{
ll mid = (lo+hi-1)/2;
pos += d * mid;
s = min(s, pos);
lo = mid+1, d *= -1;
}
s = -s;
// ok ideme robit realne binarne vyhladavanie, zaciname na s
query(s);
lo = 1, hi = n, d = 1;
while (lo < hi)
{
ll mid = (lo+hi-1)/2;
s += d * mid;
if (query(s)) hi = mid;
else lo = mid+1;
d *= -1;
}
cout << "= " << lo << endl;
return 0;
}
# | 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... |