結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,400 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 26 ms
24,276 KB
testcase_06 AC 27 ms
23,700 KB
testcase_07 AC 26 ms
24,048 KB
testcase_08 AC 27 ms
24,072 KB
testcase_09 AC 26 ms
24,264 KB
testcase_10 AC 26 ms
23,844 KB
testcase_11 AC 26 ms
23,472 KB
testcase_12 WA -
testcase_13 AC 28 ms
24,288 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 26 ms
23,412 KB
testcase_17 AC 25 ms
23,880 KB
testcase_18 AC 28 ms
23,436 KB
testcase_19 AC 27 ms
23,424 KB
testcase_20 WA -
testcase_21 AC 25 ms
24,072 KB
testcase_22 AC 26 ms
23,556 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 30 ms
24,048 KB
testcase_26 AC 27 ms
23,652 KB
testcase_27 WA -
testcase_28 AC 27 ms
23,556 KB
testcase_29 AC 29 ms
24,060 KB
testcase_30 AC 27 ms
24,288 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 25 ms
24,072 KB
testcase_34 AC 25 ms
24,384 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