結果
問題 | No.967 引き算をして門松列(その2) |
ユーザー | siman |
提出日時 | 2022-11-15 12:37:56 |
言語 | Ruby (3.3.0) |
結果 |
AC
|
実行時間 | 136 ms / 2,000 ms |
コード長 | 1,623 bytes |
コンパイル時間 | 150 ms |
コンパイル使用メモリ | 7,552 KB |
実行使用メモリ | 12,544 KB |
最終ジャッジ日時 | 2024-09-16 12:27:45 |
合計ジャッジ時間 | 2,487 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 90 ms
12,032 KB |
testcase_01 | AC | 88 ms
12,160 KB |
testcase_02 | AC | 87 ms
12,288 KB |
testcase_03 | AC | 108 ms
12,288 KB |
testcase_04 | AC | 107 ms
12,288 KB |
testcase_05 | AC | 108 ms
12,160 KB |
testcase_06 | AC | 108 ms
12,288 KB |
testcase_07 | AC | 108 ms
12,160 KB |
testcase_08 | AC | 119 ms
12,416 KB |
testcase_09 | AC | 136 ms
12,544 KB |
testcase_10 | AC | 133 ms
12,288 KB |
testcase_11 | AC | 135 ms
12,416 KB |
コンパイルメッセージ
Main.rb:117: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
T = gets.to_i def f1(a, b, c, x, y, z) cost = 0 if a >= b diff = a - b + 1 cost += x * diff a -= diff end if b <= c diff = c - b + 1 cost += z * diff c -= diff end if a <= c diff = c - a + 1 cost += z * diff c -= diff end return Float::INFINITY if a <= 0 return Float::INFINITY if c <= 0 cost end def f2(a, b, c, x, y, z) cost = 0 if a >= b diff = a - b + 1 cost += x * diff a -= diff end if b <= c diff = c - b + 1 cost += z * diff c -= diff end if a >= c diff = a - c + 1 cost += x * diff a -= diff end return Float::INFINITY if a <= 0 return Float::INFINITY if c <= 0 cost end def f3(a, b, c, x, y, z) cost = 0 if a <= c diff = c - a + 1 cost += z * diff c -= diff end if a <= b diff = b - a + 1 cost += y * diff b -= diff end if b >= c diff = b - c + 1 cost += y * diff b -= diff end return Float::INFINITY if b <= 0 return Float::INFINITY if c <= 0 cost end def f4(a, b, c, x, y, z) cost = 0 if a >= c diff = a - c + 1 cost += x * diff a -= diff end if a <= b diff = b - a + 1 cost += y * diff b -= diff end if b >= c diff = b - c + 1 cost += y * diff b -= diff end return Float::INFINITY if b <= 0 return Float::INFINITY if a <= 0 cost end T.times do a, b, c, x, y, z = gets.split.map(&:to_i) res = [f1(a, b, c, x, y, z), f2(a, b, c, x, y, z), f3(a, b, c, x, y, z), f4(a, b, c, x, y, z)].min if res == Float::INFINITY puts -1 else puts res end end