結果

問題 No.2753 鳩の巣原理
ユーザー eve__fuyuki
提出日時 2024-05-10 22:06:22
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,171 bytes
コンパイル時間 1,779 ms
コンパイル使用メモリ 202,240 KB
最終ジャッジ日時 2025-02-21 12:48:37
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
void fast_io() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}
bool debug = false;

vector<int> cnt;
int query(int x) {
    cout << "? " << x << endl;
    if (debug) {
        return cnt[x - 1];
    } else {
        int c;
        cin >> c;
        return c;
    }
}
int main() {
    fast_io();
    int n;
    cin >> n;
    if (debug) {
        cnt.resize(n);
        uniform_int_distribution<int> dist(1, n - 1);
        random_device rd;
        mt19937 mt(rd());
        for (int i = 0; i < n; i++) {
            cnt[i] = dist(mt);
        }
        sort(cnt.begin(), cnt.end());
    }
    int l = 1, r = n;
    int lcnt = query(l);
    int rcnt = query(r);

    for (int i = 0; i < 8; i++) {
        if (l + 1 == r) {
            int c = query(l);
            continue;
        }
        int mid = (l + r) / 2;
        int c = query(mid);
        if (mid - l > c - lcnt) {
            r = mid;
            rcnt = c;
        } else {
            l = mid;
            lcnt = c;
        }
    }
    if (debug) {
        assert(cnt[l - 1] == cnt[r - 1]);
    }
    cout << "Yes " << l << " " << r << endl;
}
0