結果

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

ソースコード

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 - 4) {
        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 if (res == -1) {
                    l = max(0, l - 5);
                while (1) {
                    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;
    }
    while (1) {
        cout << "? " << l << endl;
        cin >> res;
        if (res == 0) {
            if (l == 0) {
                cout << "! 0" << endl;
                return 0;
            } else {
                cout << "! " << l - 1 << endl;
                return 0;
            }
        }
    }
}
0