結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 28 ms
23,628 KB
testcase_02 AC 29 ms
23,424 KB
testcase_03 AC 28 ms
23,940 KB
testcase_04 AC 28 ms
23,736 KB
testcase_05 AC 29 ms
23,952 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 28 ms
24,180 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 28 ms
23,952 KB
testcase_15 AC 30 ms
24,180 KB
testcase_16 AC 28 ms
23,412 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 28 ms
23,832 KB
testcase_20 WA -
testcase_21 AC 29 ms
23,844 KB
testcase_22 AC 28 ms
23,628 KB
testcase_23 WA -
testcase_24 AC 29 ms
23,940 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 29 ms
23,280 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