結果
| 問題 |
No.602 隠されていたゲーム2
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-03 17:53:33 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 1,352 ms / 2,000 ms |
| コード長 | 1,045 bytes |
| コンパイル時間 | 46 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 25,216 KB |
| 最終ジャッジ日時 | 2024-12-16 00:05:42 |
| 合計ジャッジ時間 | 5,832 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
コンパイルメッセージ
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
ソースコード
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