結果

問題 No.2753 鳩の巣原理
ユーザー haihamabossu
提出日時 2024-05-10 22:49:22
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 753 bytes
コンパイル時間 1,793 ms
コンパイル使用メモリ 196,124 KB
最終ジャッジ日時 2025-02-21 13:04:34
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

ll query(ll x) {
  cout << "? " << x << endl;
  cout.flush();
  ll res;
  cin >> res;
  return res;
}

void solve() {
  ll n;
  cin >> n;
  vector<ll> cnt(n + 10, -1);
  ll l = 0, r = n + 1, q = 10;
  cnt[l] = 0, cnt[r] = n;
  while (l + 1 < r) {
    ll m = (l + r) / 2;
    cnt[m] = query(m);
    q--;
    if (cnt[m] - cnt[l] < m - l) {
      r = m;
    } else {
      l = m;
    }
  }
  while (q--)
    query(1);
  cout << "Yes " << l << ' ' << r << endl;
  cout.flush();
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  int T = 1;
  for (int t = 0; t < T; t++) {
    solve();
  }
  return 0;
}
0