結果

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

テストケース

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

ソースコード

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;
            cur += ((max - min) / 2) - 1;
        }
        else
        {
            max = cur - 1;
            cur -= ((max - min) / 2) - 1;
        }

        max--;
        min--;
    }
    
    std::cout << "! " << cur + i << std::endl;
    
    return 0;
}
0