結果

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

テストケース

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

ソースコード

diff #

def ternary_search_tree(left, right)
  loop_cnt = 24

  loop_cnt.times do
    if yield((left * 2 + right) / 3) < yield((left + right * 2) / 3)
      right = (left + right * 2) / 3
    else
      left = (left * 2 + right) / 3
    end
  end

  (left + right) / 2
end

cy = 0
cx = 0

STDOUT.puts("%d %d" % [cx, cy])
STDOUT.flush
current_d = gets.to_i

if current_d == 0
  exit
end

cx = ternary_search_tree(0, 100_001) { |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_001) { |y|
  STDOUT.puts("%d %d" % [cx, y])
  STDOUT.flush
  d = gets.to_i

  if d == 0
    exit
  end

  d
}
0