結果
| 問題 |
No.966 引き算をして門松列(その1)
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2020-12-18 15:56:12 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 106 ms / 2,000 ms |
| コード長 | 826 bytes |
| コンパイル時間 | 286 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 12,288 KB |
| 最終ジャッジ日時 | 2024-09-21 09:11:42 |
| 合計ジャッジ時間 | 1,870 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 |
コンパイルメッセージ
Main.rb:68: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
T = gets.to_i
# /\ cost
def f(a, b, c)
cost = 0
if a >= b
d = a - b + 1
a -= d
cost += d
end
if c >= b
d = c - b + 1
c -= d
cost += d
end
if a == c
cost += 1
a -= 1
end
return Float::INFINITY if a <= 0 || c <= 0
cost
end
# \/ cost
def g(a, b, c)
cost = 0
if a == c
a -= 1
cost += 1
end
return Float::INFINITY if a <= 0
if a <= b
d = b - a + 1
b -= d
cost += d
end
if c <= b
d = b - c + 1
b -= d
cost += d
end
return Float::INFINITY if b <= 0
cost
end
T.times do
a, b, c = gets.split.map(&:to_i)
if a > b && c > b && a != c
puts 0
elsif a < b && c < b && a != c
puts 0
else
v = [f(a, b, c), g(a, b, c)].min
if v == Float::INFINITY
puts -1
else
puts v
end
end
end
siman