結果

問題 No.602 隠されていたゲーム2
ユーザー cympfhcympfh
提出日時 2017-12-03 17:53:33
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,417 ms / 2,000 ms
コード長 1,045 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 11,432 KB
実行使用メモリ 27,984 KB
最終ジャッジ日時 2023-08-22 05:40:02
合計ジャッジ時間 6,492 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,268 KB
testcase_01 AC 84 ms
15,256 KB
testcase_02 AC 84 ms
15,032 KB
testcase_03 AC 84 ms
15,264 KB
testcase_04 AC 81 ms
15,224 KB
testcase_05 AC 82 ms
15,108 KB
testcase_06 AC 84 ms
15,064 KB
testcase_07 AC 82 ms
15,252 KB
testcase_08 AC 82 ms
15,112 KB
testcase_09 AC 82 ms
15,292 KB
testcase_10 AC 82 ms
15,108 KB
testcase_11 AC 82 ms
15,212 KB
testcase_12 AC 83 ms
15,196 KB
testcase_13 AC 85 ms
15,072 KB
testcase_14 AC 83 ms
15,296 KB
testcase_15 AC 83 ms
15,192 KB
testcase_16 AC 262 ms
16,796 KB
testcase_17 AC 132 ms
18,276 KB
testcase_18 AC 158 ms
23,444 KB
testcase_19 AC 186 ms
26,000 KB
testcase_20 AC 1,417 ms
27,984 KB
testcase_21 AC 1,329 ms
27,692 KB
testcase_22 AC 156 ms
24,708 KB
testcase_23 AC 170 ms
26,120 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:34: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:45: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:75: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:15: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

def index(xs, x)
  left = 0
  right = xs.size
  100.times do
    i = (left + right) / 2
    if xs[i] < x
      left = i
    else
      right = i
    end
  end
  left
end

n = gets.to_i
ds = gets.chomp.split.map(&:to_i).sort
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?).sort
  os = ds.select(&:odd?).sort
  e_max = es.max
  o_max = os.max

  if e_max == nil or o_max == nil
    p -1
    exit
  end

  os.each do |d|
    diff = (r - d).abs
    i = index(es, diff)
    (i-3..i+3).each do |j|
      d2 = es[j]
      next if d2 == nil
      if (d - d2).abs <= r and r <= d2 + d2
        p 2
        exit
      end
    end
  end

  es.each do |d|
    diff = (r - d).abs
    i = index(os, diff)
    (i-3..i+3).each do |j|
      d2 = os[j]
      next if d2 == nil
      if (d - d2).abs <= r and r <= d2 + d2
        p 2
        exit
      end
    end
  end

  p -1

end
0