結果

問題 No.253 ロウソクの長さ
ユーザー tottoripapertottoripaper
提出日時 2015-07-25 00:20:18
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,059 bytes
コンパイル時間 393 ms
コンパイル使用メモリ 52,168 KB
実行使用メモリ 24,456 KB
平均クエリ数 34.19
最終ジャッジ日時 2023-09-23 05:04:44
合計ジャッジ時間 5,983 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 27 ms
23,532 KB
testcase_02 AC 28 ms
24,192 KB
testcase_03 AC 26 ms
23,952 KB
testcase_04 AC 26 ms
24,300 KB
testcase_05 AC 26 ms
24,312 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 24 ms
23,316 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 25 ms
23,940 KB
testcase_15 AC 29 ms
23,952 KB
testcase_16 AC 27 ms
23,544 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 26 ms
24,036 KB
testcase_20 WA -
testcase_21 AC 28 ms
24,012 KB
testcase_22 AC 25 ms
24,012 KB
testcase_23 WA -
testcase_24 AC 28 ms
23,724 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 26 ms
23,940 KB
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

int ask(int n){
    std::cout << "? " << n << std::endl;
    int res = 0;
    std::cin >> res;
    return res;
}

void answer(int n){
    std::cout << "! " << n << std::endl;
}

int main(){
    int lb = 10, ub = 1000000001;
    int res;
    
    std::cout << "? 100" << std::endl;
    std::cin >> res;

    if(res == 0){
        answer(res);
        return 0;
    }else if(res == -1){
        for(int i=1;i<100;i++){
            res = ask(0);
            if(res == 0){
                answer(i);
                return 0;
            }
        }
    }else{
        for(int i=0;i<100;i++){
            int mid = (lb + ub) / 2;
            std::cout << "? " << mid << std::endl;
            int res;
            std::cin >> res;
            if(res == 0){
                std::cout << "! " << (mid + i) << std::endl;
                return 0;
            }else if(res == 1){
                lb = mid;
            }else{
                ub = mid;
            }

            lb = std::max(0, lb-1);
            ub = ub - 1;
        }

    }
}
0