結果

問題 No.513 宝探し2
ユーザー simansiman
提出日時 2020-12-10 17:26:46
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 548 bytes
コンパイル時間 44 ms
コンパイル使用メモリ 11,368 KB
実行使用メモリ 31,616 KB
平均クエリ数 71.17
最終ジャッジ日時 2023-09-24 09:20:38
合計ジャッジ時間 4,160 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

  left
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