結果

問題 No.253 ロウソクの長さ
ユーザー lunnearlunnear
提出日時 2019-01-28 05:12:04
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 744 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 51,824 KB
実行使用メモリ 24,492 KB
平均クエリ数 69.86
最終ジャッジ日時 2023-09-23 16:46:07
合計ジャッジ時間 6,753 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 25 ms
24,300 KB
testcase_02 AC 27 ms
23,424 KB
testcase_03 AC 24 ms
23,568 KB
testcase_04 AC 25 ms
23,364 KB
testcase_05 AC 25 ms
23,316 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 23 ms
23,664 KB
testcase_15 AC 25 ms
23,340 KB
testcase_16 AC 24 ms
23,556 KB
testcase_17 AC 22 ms
23,436 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 24 ms
24,312 KB
testcase_22 AC 24 ms
23,760 KB
testcase_23 WA -
testcase_24 AC 26 ms
24,276 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 24 ms
23,556 KB
testcase_35 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>

int q(int x)
{
    int ret;
    
    std::cout << "? " << x << std::endl;
    std::cout << std::flush;
    
    std::cin >> ret;
    return ret;
}

int main()
{
    int a;
    a = q(100);
    
    if(a == 0)
    {
        std::cout << "! 100" << std::endl;
        return 0;
    }
    
    int min, max, cur, i;
    min = 1;
    max = (a > 0)? 1000000000:100;
    cur = (max - min) / 2;
    i = 1;
    
    for(; i < 100; i++)
    {
        a = q(cur);
        if(a == 0)
            break;
        
        if(a > 0)
            min = cur + 1;
        
        if(a < 0)
            max = cur - 1;
        
        cur = ((max - min) / 2) - 1;
    }
    
    std::cout << "! " << cur + i << std::endl;
    
    return 0;
}
0