結果

問題 No.467 隠されていたゲーム
ユーザー cympfhcympfh
提出日時 2017-05-18 17:53:46
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 513 bytes
コンパイル時間 363 ms
コンパイル使用メモリ 11,884 KB
実行使用メモリ 18,472 KB
最終ジャッジ日時 2023-10-18 23:12:03
合計ジャッジ時間 4,559 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
16,100 KB
testcase_01 AC 90 ms
16,100 KB
testcase_02 AC 85 ms
16,100 KB
testcase_03 AC 84 ms
16,100 KB
testcase_04 AC 85 ms
16,100 KB
testcase_05 AC 87 ms
16,100 KB
testcase_06 AC 84 ms
16,100 KB
testcase_07 AC 86 ms
16,100 KB
testcase_08 RE -
testcase_09 AC 87 ms
16,104 KB
testcase_10 AC 85 ms
16,104 KB
testcase_11 AC 85 ms
16,104 KB
testcase_12 AC 86 ms
16,104 KB
testcase_13 AC 86 ms
16,104 KB
testcase_14 AC 86 ms
16,104 KB
testcase_15 AC 85 ms
16,100 KB
testcase_16 AC 87 ms
16,104 KB
testcase_17 AC 86 ms
16,104 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 AC 90 ms
16,148 KB
testcase_22 AC 88 ms
16,104 KB
testcase_23 AC 88 ms
16,104 KB
testcase_24 AC 88 ms
16,104 KB
testcase_25 AC 89 ms
16,104 KB
testcase_26 AC 87 ms
16,104 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def solve(x0, y0, x, y, ds, ac)
  return ac if x0 == x && y0 == y
  ell = [(x - x0).abs, (y - y0).abs].max
  ds.each do |d|
    return ac + 1 if d == ell
  end

  maxd = ds[0]

  if ell >= 2 * maxd
    if x0 < x
      x0 += maxd
    else
      x0 -= maxd
    end
    if y0 < y
      y0 += maxd
    else
      y0 -= maxd
    end
    return solve(x0, y0, x, y, ds, ac + 1)
  end

  ac + 2
end

_ = gets.to_i
ds = gets.split.map(&:to_i)
ds.sort!
ds.reverse!
x, y = gets.split.map(&:to_i)

p solve(0, 0, x, y, ds, 0)
0