結果

問題 No.253 ロウソクの長さ
ユーザー xuzijian629
提出日時 2018-10-27 01:18:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,213 bytes
コンパイル時間 1,997 ms
コンパイル使用メモリ 192,688 KB
最終ジャッジ日時 2025-01-06 14:48:10
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int l = 0, r = 1e9, res;
    cout << "? " << r << endl;
    cin >> res;
    if (res == 0) {
        cout << "! " << r - 1 << endl;
        return 0;
    }

    int hoge = 0;
    while (l < r - 1) {
        if (hoge) {
            cout << "? " << l << endl;
            cin >> res;
            if (res == 0) {
                if (l == 0) {
                    cout << "! 0" << endl;
                    return 0;
                } else {
                    cout << "! " << l - 1 << endl;
                    return 0;
                }
            }
        } else {
            int m = (l + r) / 2;
            cout << "? " << m << endl;
            cin >> res;
            if (res == 1) {
                l = m;
            } else if (res == -1) {
                r = m;
            } else {
                if (m == 0) {
                    cout << "! 0" << endl;
                    return 0;
                } else {
                    cout << "! " << m - 1 << endl;
                    return 0;
                }   
            }
        }
        hoge = 1 - hoge;
    }
}
0