結果

問題 No.246 質問と回答
ユーザー takumi-onisitakumi-onisi
提出日時 2021-05-05 13:38:00
言語 Ruby
(3.3.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 762 bytes
コンパイル時間 476 ms
コンパイル使用メモリ 11,196 KB
実行使用メモリ 31,472 KB
平均クエリ数 30.90
最終ジャッジ日時 2023-09-23 20:38:21
合計ジャッジ時間 5,515 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
31,472 KB
testcase_01 AC 122 ms
31,292 KB
testcase_02 AC 119 ms
30,856 KB
testcase_03 AC 123 ms
31,020 KB
testcase_04 AC 118 ms
30,804 KB
testcase_05 AC 119 ms
30,876 KB
testcase_06 AC 120 ms
31,360 KB
testcase_07 AC 120 ms
30,968 KB
testcase_08 AC 119 ms
31,000 KB
testcase_09 AC 119 ms
30,844 KB
testcase_10 AC 116 ms
30,868 KB
testcase_11 AC 117 ms
30,784 KB
testcase_12 AC 115 ms
30,876 KB
testcase_13 AC 119 ms
31,172 KB
testcase_14 AC 117 ms
31,340 KB
testcase_15 AC 121 ms
30,656 KB
testcase_16 AC 122 ms
31,260 KB
testcase_17 AC 122 ms
31,000 KB
testcase_18 AC 120 ms
30,696 KB
testcase_19 AC 117 ms
30,952 KB
testcase_20 AC 118 ms
31,344 KB
testcase_21 AC 120 ms
31,268 KB
testcase_22 AC 119 ms
31,156 KB
testcase_23 AC 117 ms
31,280 KB
testcase_24 AC 122 ms
31,288 KB
testcase_25 AC 122 ms
31,332 KB
testcase_26 AC 117 ms
30,956 KB
testcase_27 AC 120 ms
31,236 KB
testcase_28 AC 120 ms
31,368 KB
testcase_29 AC 118 ms
31,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# findFavNum(a,b)は[a,b)の区間について探索する
def findFavNum(a,b)

    if a<b then
        range_left = a
        range_right = b
    else
        range_left = b
        range_right = a
    end
    
    middle = ((range_left-range_right).abs)/2 + range_left
    puts("? #{middle}")
    STDOUT.flush
    if gets.to_i == 1 then
        if (middle-range_right).abs==1 then
            puts("! #{middle}")
            STDOUT.flush
            return
        else 
            findFavNum(middle,range_right)
        end
    else
        if (range_left-middle).abs==1 then
            puts("! #{range_left}")
            STDOUT.flush
            return
        else 
            findFavNum(range_left,middle)
        end
    end
end

findFavNum(1,10**9+1)
0