結果

問題 No.968 引き算をして門松列(その3)
ユーザー 0w10w1
提出日時 2020-01-16 14:54:23
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 600 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 11,452 KB
実行使用メモリ 15,400 KB
最終ジャッジ日時 2023-09-05 23:38:36
合計ジャッジ時間 3,581 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
15,220 KB
testcase_01 AC 76 ms
15,028 KB
testcase_02 AC 75 ms
15,104 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

t = gets.to_i
t.times do
  a, b, c, x, y, z = gets.split.map &:to_i

  d = [[0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1]].map { |r|
    ps = (0...3).map { |i| r.find_index { |v| v == i } }
    vs = (0...3).map { |i| [a, b, c][ps[i]] }
    cs = (0...3).map { |i| [x, y, z][ps[i]] }
    s, t, u, v = *vs, 0
    if t <= s
      q = s + 1 - t
      v += q * cs[0]
      s -= q
      u -= q
    end
    if u <= t
      q = t + 1 - u
      v += q * cs[1]
      s -= q
      t -= q
    end
    next Float::INFINITY if [s, t, u].any? { |q| q < 1 }
    v
  } .min

  d = -1 if d == Float::INFINITY
  puts d
end
0