結果

問題 No.602 隠されていたゲーム2
ユーザー cympfh
提出日時 2017-12-02 02:23:55
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 533 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 22,528 KB
最終ジャッジ日時 2024-11-28 02:25:06
合計ジャッジ時間 3,308 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16 WA * 5
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:13: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:21: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:33: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:1: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

n = gets.to_i
ds = gets.chomp.split.map(&:to_i).sort.reverse
x, y = gets.chomp.split.map(&:to_i)
r = x.abs + y.abs

if ds.any? {|d| d == r}
  p 1
elsif r.even?
  d_max = ds[0]
  if r <= d_max + d_max
    p 2
  else
    p -1
  end
else

  es = ds.select(&:even?)
  os = ds.select(&:odd?)

  if es.size.zero? or os.size.zero?
    p -1
    exit
  end

  e_max = es[0]
  o_max = os[0]

  if es.any? {|d| d - o_max <= r and r <= d + o_max}
    p 2
  elsif os.any? {|d| d - e_max <= r and r <= d + e_max}
    p 2
  else
    p -1
  end
end
0