結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
23,568 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 23 ms
23,568 KB
testcase_06 AC 25 ms
23,592 KB
testcase_07 AC 24 ms
23,952 KB
testcase_08 AC 25 ms
23,580 KB
testcase_09 AC 24 ms
23,940 KB
testcase_10 AC 24 ms
23,772 KB
testcase_11 AC 24 ms
24,288 KB
testcase_12 WA -
testcase_13 AC 23 ms
24,048 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 23 ms
24,252 KB
testcase_17 AC 23 ms
23,388 KB
testcase_18 AC 24 ms
24,252 KB
testcase_19 AC 22 ms
23,532 KB
testcase_20 WA -
testcase_21 AC 23 ms
23,964 KB
testcase_22 AC 23 ms
23,940 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 24 ms
23,820 KB
testcase_26 AC 25 ms
24,420 KB
testcase_27 WA -
testcase_28 AC 24 ms
23,328 KB
testcase_29 AC 24 ms
24,252 KB
testcase_30 AC 24 ms
24,276 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 27 ms
23,952 KB
testcase_34 AC 23 ms
23,568 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;
    
    int p = 100, pp = -1;
    
    for(; i < 100; i++)
    {
        a = q(cur);
        if(a == 0)
            break;
        
        pp = p;
        p = cur;
        
        if(a > 0)
        {
            min = cur + 1;
            cur += ((max - min) / 2);
        }
        else
        {
            max = cur - 1;
            cur -= ((max - min) / 2) - 1;
        }
        
        if(cur == (p - 1) && cur == (pp - 2))
            cur--;

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