Submission #258478

#TimeUsernameProblemLanguageResultExecution timeMemory
258478quocnguyen1012Colors (BOI20_colors)C++14
100 / 100
2 ms512 KiB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2e5 + 5, mod = 1e9 + 7;

int go(ll x)
{
  cout << "? " << x << endl;
  int v; cin >> v;
  return v;
}

void solve(void)
{
  ll n; cin >> n;

  vector<ll> path;

  ll lo = 1, hi = n - 1;
  while(lo <= hi){
    ll mid = (lo + hi) / 2;
    path.pb(mid);
    if(lo == hi && mid == n - 1) break;
    lo = mid + 1;
  }

  ll st = n; int go_left = 1;
  reverse(path.begin(), path.end());
  for(auto i : path){
    if(go_left) st -= i;
    else st += i;
    go_left ^= 1;
  }
  go(st);
  lo = 1, hi = n - 1;
  while(lo <= hi){
    ll mid = (lo + hi) / 2;
    if(go_left) st -= mid;
    else st += mid;
    if(go(st)) hi = mid - 1;
    else lo = mid + 1;
    go_left ^= 1;
  }
  cout << "= " << lo << endl;
}

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  /*#ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL*/
  int tc; tc = 1;
  while(tc--){
    solve();
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...