結果

問題 No.513 宝探し2
ユーザー cympfhcympfh
提出日時 2017-05-05 22:38:20
言語 Ruby
(3.3.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 532 bytes
コンパイル時間 49 ms
コンパイル使用メモリ 11,560 KB
実行使用メモリ 31,484 KB
平均クエリ数 67.33
最終ジャッジ日時 2023-09-24 01:03:02
合計ジャッジ時間 2,394 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
30,880 KB
testcase_01 AC 99 ms
31,052 KB
testcase_02 AC 98 ms
30,888 KB
testcase_03 AC 101 ms
31,392 KB
testcase_04 AC 98 ms
30,848 KB
testcase_05 AC 100 ms
30,968 KB
testcase_06 AC 98 ms
31,484 KB
testcase_07 AC 97 ms
30,864 KB
testcase_08 AC 103 ms
31,044 KB
testcase_09 AC 103 ms
31,460 KB
testcase_10 AC 103 ms
31,008 KB
testcase_11 AC 101 ms
30,816 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

M = 100000

def get(x, y)

  x = [M, [0, x].max].min
  y = [M, [0, y].max].min

  puts "#{x} #{y}"
  STDOUT.flush
  d = gets.to_i
  return d
end

y = M / 2
left = 0
right = M

while right - left > 2
  x1 = (left + left + right) / 3
  x2 = (left + right + right) / 3
  d1 = get(x1, y)
  d2 = get(x2, y)
  if d1 < d2
    right = x2
  else
    left = x1
  end
end

mn_d = M * M
mn_x = left

((left - 5)..(left + 5)).each do |x|
  d = get(x, y)
  if d < mn_d
    mn_d = d
    mn_x = x
  end
end

get(mn_x, y + mn_d)
get(mn_x, y - mn_d)
0