結果

問題 No.968 引き算をして門松列(その3)
ユーザー 0w10w1
提出日時 2020-01-16 15:06:44
言語 Ruby
(3.3.0)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 600 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 11,552 KB
実行使用メモリ 15,492 KB
最終ジャッジ日時 2023-09-05 23:59:30
合計ジャッジ時間 3,029 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,080 KB
testcase_01 AC 78 ms
15,364 KB
testcase_02 AC 79 ms
15,240 KB
testcase_03 AC 149 ms
15,452 KB
testcase_04 AC 157 ms
15,324 KB
testcase_05 AC 153 ms
15,248 KB
testcase_06 AC 155 ms
15,492 KB
testcase_07 AC 153 ms
15,288 KB
testcase_08 AC 199 ms
15,288 KB
testcase_09 AC 256 ms
15,192 KB
testcase_10 AC 297 ms
15,284 KB
testcase_11 AC 252 ms
15,452 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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| [y, z, x][ps[i]] }
    s, t, u, v = *vs, 0
    if t <= s
      q = s + 1 - t
      v += q * cs[1]
      s -= q
      u -= q
    end
    if u <= t
      q = t + 1 - u
      v += q * cs[2]
      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