結果

問題 No.253 ロウソクの長さ
ユーザー machy
提出日時 2015-07-25 00:34:54
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 989 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 56,352 KB
実行使用メモリ 25,220 KB
平均クエリ数 30.53
最終ジャッジ日時 2024-07-16 20:50:45
合計ジャッジ時間 3,547 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

using namespace std;

int main(){
    int left = 10;
    int right = 1000000001;
    int cnt = 1;
    int ans;
    cout << "? 100" << endl;
    cout.flush();
    cin >> ans;
    if(ans == -1){
        for(int i = 0; i < 99; i++){
            cout << "? 9" << endl;
            cout.flush();
            cin >> ans;
            if(ans == 0){
                cout << "! " << 10 + i << endl;
                break;
            }
        }
        return 0;
    }else if(ans == 0){
        cout << "! 100" << endl;
        return 0;
    }
    while(left + 1 < right){
        int middle = (left + right) / 2;
        cout << "? " << max(0, middle - cnt) << endl;
        cout.flush();
        int ans;
        cin >> ans;
        if(ans == -1){
            right = middle;
        }else if(ans == 0){
            left = middle;
            break;
        }else{
            left = middle+1;
        }
        cnt++;
    }
    cout << "! " << left << endl;
    return 0;
}
0