結果

問題 No.253 ロウソクの長さ
ユーザー face4face4
提出日時 2018-11-15 12:57:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 814 bytes
コンパイル時間 500 ms
コンパイル使用メモリ 62,728 KB
実行使用メモリ 24,540 KB
平均クエリ数 36.61
最終ジャッジ日時 2023-09-23 16:34:29
合計ジャッジ時間 5,473 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
24,312 KB
testcase_01 AC 27 ms
23,604 KB
testcase_02 AC 28 ms
23,892 KB
testcase_03 AC 27 ms
23,340 KB
testcase_04 AC 26 ms
23,484 KB
testcase_05 AC 28 ms
24,072 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 27 ms
24,084 KB
testcase_09 AC 25 ms
23,592 KB
testcase_10 WA -
testcase_11 AC 25 ms
24,312 KB
testcase_12 AC 26 ms
24,072 KB
testcase_13 WA -
testcase_14 AC 25 ms
23,592 KB
testcase_15 AC 28 ms
23,976 KB
testcase_16 AC 26 ms
24,084 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 25 ms
23,352 KB
testcase_20 WA -
testcase_21 AC 26 ms
23,592 KB
testcase_22 AC 25 ms
23,352 KB
testcase_23 WA -
testcase_24 AC 28 ms
23,688 KB
testcase_25 WA -
testcase_26 AC 26 ms
24,072 KB
testcase_27 AC 25 ms
24,192 KB
testcase_28 AC 25 ms
23,700 KB
testcase_29 WA -
testcase_30 AC 25 ms
24,072 KB
testcase_31 AC 25 ms
24,372 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 25 ms
23,616 KB
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
using namespace std;

int ask(int Y){
	cout << "? " << Y << endl << flush;
	int res;
	cin >> res;
	return res;
}

void answer(int Y){
    cout << "! " << Y << endl << flush;
}

int main(){
    if(ask(100) <= 0){
        for(int i = 1;;i++){
            if(ask(0) == 0){
                answer(i);
                return 0;
            }
        }
    }

    // l inclusive, r exclusive
    int l = 10, r = 1000000001;
    int cnt = 1;

    while(r-l > 1){
        int mid = (l+r)/2;
        switch(ask(mid)){
            case -1:
                r = mid-1;
                break;
            case 1:
                l = mid;
                break;
            case 0:
                answer(mid+cnt);
                return 0;
        }
        cnt++;
    }

    answer(l + cnt);
    return 0;
}
0