結果

問題 No.968 引き算をして門松列(その3)
ユーザー simansiman
提出日時 2023-01-05 12:25:57
言語 Ruby
(3.3.0)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 1,473 bytes
コンパイル時間 792 ms
コンパイル使用メモリ 11,484 KB
実行使用メモリ 15,552 KB
最終ジャッジ日時 2023-08-19 10:19:25
合計ジャッジ時間 4,193 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,168 KB
testcase_01 AC 79 ms
15,164 KB
testcase_02 AC 78 ms
15,224 KB
testcase_03 AC 96 ms
15,264 KB
testcase_04 AC 96 ms
15,272 KB
testcase_05 AC 96 ms
15,552 KB
testcase_06 AC 97 ms
15,344 KB
testcase_07 AC 97 ms
15,184 KB
testcase_08 AC 110 ms
15,328 KB
testcase_09 AC 123 ms
15,400 KB
testcase_10 AC 124 ms
15,448 KB
testcase_11 AC 125 ms
15,296 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:85: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

T = gets.to_i

def ptn1(a, b, c, x, y, z)
  cost = 0
  diff = [0, c - a + 1].max
  cost += y * diff
  b -= diff
  c -= diff

  diff = [0, a - b + 1, c - b + 1].max
  cost += z * diff
  a -= diff
  c -= diff

  return Float::INFINITY if a <= 0
  return Float::INFINITY if b <= 0
  return Float::INFINITY if c <= 0

  cost
end

def ptn2(a, b, c, x, y, z)
  cost = 0
  diff = [0, a - c + 1].max
  cost += x * diff
  a -= diff
  b -= diff

  diff = [0, a - b + 1, c - b + 1].max
  cost += z * diff
  a -= diff
  c -= diff

  return Float::INFINITY if a <= 0
  return Float::INFINITY if b <= 0
  return Float::INFINITY if c <= 0

  cost
end

def ptn3(a, b, c, x, y, z)
  cost = 0
  diff = [0, b - a + 1].max
  cost += y * diff
  b -= diff
  c -= diff

  diff = [0, a - c + 1].max
  cost += x * diff
  a -= diff
  b -= diff

  return Float::INFINITY if a <= 0
  return Float::INFINITY if b <= 0
  return Float::INFINITY if c <= 0

  cost
end

def ptn4(a, b, c, x, y, z)
  cost = 0
  diff = [0, b - c + 1].max
  cost += x * diff
  a -= diff
  b -= diff

  diff = [0, c - a + 1].max
  cost += y * diff
  b -= diff
  c -= diff

  return Float::INFINITY if a <= 0
  return Float::INFINITY if b <= 0
  return Float::INFINITY if c <= 0

  cost
end

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

  ans = [ptn1(a, b, c, x, y, z), ptn2(a, b, c, x, y, z), ptn3(a, b, c, x, y, z), ptn4(a, b, c, x, y, z)].min

  if ans == Float::INFINITY
    puts -1
  else
    puts ans
  end
end
0