結果
| 問題 | No.602 隠されていたゲーム2 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2017-12-03 05:28:32 | 
| 言語 | Ruby (3.4.1) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 546 bytes | 
| コンパイル時間 | 53 ms | 
| コンパイル使用メモリ | 7,552 KB | 
| 実行使用メモリ | 21,248 KB | 
| 最終ジャッジ日時 | 2024-11-28 08:32:11 | 
| 合計ジャッジ時間 | 3,700 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 17 WA * 4 | 
コンパイルメッセージ
Main.rb:20: warning: ambiguous first argument; put parentheses or a space even after `-' operator Main.rb:31: warning: ambiguous first argument; put parentheses or a space even after `-' operator Main.rb:37: warning: ambiguous first argument; put parentheses or a space even after `-' operator Main.rb:1: warning: assigned but unused variable - n Syntax OK
ソースコード
n = gets.to_i
ds = gets.chomp.split.map(&:to_i)
x, y = gets.chomp.split.map(&:to_i)
r = x.abs + y.abs
if r.zero?
  p 0
elsif ds.any? {|d| d == r}
  p 1
elsif r.even?
  d_max = ds.max
  if r <= d_max + d_max
    p 2
  else
    p -1
  end
else
  es = ds.select(&:even?)
  os = ds.select(&:odd?)
  e_max = es.max
  o_max = os.max
  if e_max == nil or o_max == nil
    p -1
  elsif es.any? {|d| (d - o_max).abs <= r and r <= d + o_max}
    p 2
  elsif os.any? {|d| (d - e_max).abs <= r and r <= d + e_max}
    p 2
  else
    p -1
  end
end
            
            
            
        