結果

問題 No.513 宝探し2
ユーザー simansiman
提出日時 2020-12-10 17:26:28
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 545 bytes
コンパイル時間 108 ms
コンパイル使用メモリ 11,336 KB
実行使用メモリ 31,756 KB
平均クエリ数 43.58
最終ジャッジ日時 2023-09-24 09:20:28
合計ジャッジ時間 3,927 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 RE -
testcase_07 WA -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def ternary_search_tree(left, right)
  loop_cnt = 25

  loop_cnt.times do
    l = (left * 2 + right / 3.0).floor
    r = ((left + right * 2) / 3.0).ceil

    if yield(l) < yield(r)
      right = r
    else
      left = l
    end
  end

  l
end

cx = 0
cy = 0

cx = ternary_search_tree(0, 100_000) { |x|
  STDOUT.puts("%d %d" % [x, cy])
  STDOUT.flush
  d = gets.to_i

  if d == 0
    exit
  end

  d
}

cy = ternary_search_tree(0, 100_000) { |y|
  STDOUT.puts("%d %d" % [cx, y])
  STDOUT.flush
  d = gets.to_i

  if d == 0
    exit
  end

  d
}
0