結果

問題 No.594 壊れた宝物発見機
ユーザー maimai
提出日時 2017-11-10 22:38:47
言語 Ruby
(3.3.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 930 bytes
コンパイル時間 117 ms
コンパイル使用メモリ 11,556 KB
実行使用メモリ 31,568 KB
平均クエリ数 190.00
最終ジャッジ日時 2023-09-23 14:45:38
合計ジャッジ時間 5,589 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 201 ms
30,668 KB
testcase_01 AC 199 ms
31,284 KB
testcase_02 AC 198 ms
31,372 KB
testcase_03 AC 202 ms
31,200 KB
testcase_04 AC 197 ms
31,368 KB
testcase_05 AC 197 ms
31,568 KB
testcase_06 AC 199 ms
31,284 KB
testcase_07 AC 202 ms
31,356 KB
testcase_08 AC 200 ms
30,916 KB
testcase_09 AC 209 ms
31,076 KB
testcase_10 AC 202 ms
31,000 KB
testcase_11 AC 201 ms
31,080 KB
testcase_12 AC 204 ms
31,116 KB
testcase_13 AC 200 ms
31,256 KB
testcase_14 AC 203 ms
30,656 KB
testcase_15 AC 196 ms
31,124 KB
testcase_16 AC 197 ms
30,688 KB
testcase_17 AC 197 ms
30,672 KB
testcase_18 AC 200 ms
30,880 KB
testcase_19 AC 199 ms
30,808 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:38: warning: assigned but unused variable - dist
Syntax OK

ソースコード

diff #


def trisearch(left, right, equal = nil, &block)
    
    30.times {
        l = right - (2 * right - 2 * left) / 3
        r = right - (right - left) / 3

        lval = block.call(l)
        rval = block.call(r)
        
        if (lval <= rval)
            right = r
        else
            left = l
        end
        
        return left if (left == right)
    }
    
    best = block.call(left);
    bestidx = left;
    (left+1).upto(right){|t|
        f = block.call(t)
        if best > f
            best = f; bestidx = t
        end
    }
    return nil if equal && equal != block.call(bestidx)
    return bestidx
end



def query(x,y,z)
    puts "? #{x} #{y} #{z}"
    $>.flush
    dist = gets.to_i
end

def bye(x,y,z)
    puts "! #{x} #{y} #{z}"
    exit
end


x = y = z = 0

x = trisearch(-150,150){|t| query(t,y,z)}
y = trisearch(-150,150){|t| query(x,t,z)}
z = trisearch(-150,150){|t| query(x,y,t)}

bye(x,y,z)
0