結果

問題 No.968 引き算をして門松列(その3)
ユーザー simansiman
提出日時 2023-01-05 12:25:57
言語 Ruby
(3.3.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 1,473 bytes
コンパイル時間 434 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-11-29 01:46:36
合計ジャッジ時間 3,140 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
12,032 KB
testcase_01 AC 89 ms
12,160 KB
testcase_02 AC 86 ms
12,160 KB
testcase_03 AC 108 ms
12,288 KB
testcase_04 AC 107 ms
12,288 KB
testcase_05 AC 107 ms
12,288 KB
testcase_06 AC 108 ms
12,032 KB
testcase_07 AC 107 ms
12,160 KB
testcase_08 AC 119 ms
12,160 KB
testcase_09 AC 134 ms
12,160 KB
testcase_10 AC 136 ms
12,288 KB
testcase_11 AC 139 ms
12,288 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