結果

問題 No.967 引き算をして門松列(その2)
ユーザー 👑 obakyanobakyan
提出日時 2020-03-31 22:20:04
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 38 ms / 2,000 ms
コード長 1,539 bytes
コンパイル時間 248 ms
コンパイル使用メモリ 5,296 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-07 13:00:54
合計ジャッジ時間 1,213 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,508 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 16 ms
4,384 KB
testcase_04 AC 15 ms
4,384 KB
testcase_05 AC 15 ms
4,384 KB
testcase_06 AC 16 ms
4,384 KB
testcase_07 AC 16 ms
4,384 KB
testcase_08 AC 26 ms
4,384 KB
testcase_09 AC 38 ms
4,380 KB
testcase_10 AC 37 ms
4,380 KB
testcase_11 AC 35 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local t = io.read("*n")
for it = 1, t do
  local a, b, c = io.read("*n", "*n", "*n")
  local x, y, z = io.read("*n", "*n", "*n")
  x = 0LL + x
  y = 0LL + y
  z = 0LL + z
  local inf = 1000000007LL * 1000000007LL
  local ret = inf
  do
    -- b < a < c
    local ta, tb, tc = a, b, c
    local cost = 0LL
    if tc <= ta then
      cost = cost + x * (ta + 1 - tc)
      ta = tc - 1
    end
    if ta <= tb then
      cost = cost + y * (tb + 1 - ta)
      tb = ta - 1
    end
    if 0 < tb and cost < ret then ret = cost end
  end
  do
    -- b < c < a
    local ta, tb, tc = a, b, c
    local cost = 0LL
    if ta <= tc then
      cost = cost + z * (tc + 1 - ta)
      tc = ta - 1
    end
    if tc <= tb then
      cost = cost + y * (tb + 1 - tc)
      tb = tc - 1
    end
    if 0 < tb and cost < ret then ret = cost end
  end
  do
    -- a < c < b
    local ta, tb, tc = a, b, c
    local cost = 0LL
    if tb <= tc then
      cost = cost + z * (tc + 1 - tb)
      tc = tb - 1
    end
    if tc <= ta then
      cost = cost + x * (ta + 1 - tc)
      ta = tc - 1
    end
    if 0 < ta and cost < ret then ret = cost end
  end
  do
    -- c < a < b
    local ta, tb, tc = a, b, c
    local cost = 0LL
    if tb <= ta then
      cost = cost + x * (ta + 1 - tb)
      ta = tb - 1
    end
    if ta <= tc then
      cost = cost + z * (tc + 1 - ta)
      tc = ta - 1
    end
    if 0 < tc and cost < ret then ret = cost end
  end
  if ret == inf then
    print(-1)
  else
    local str = tostring(ret):gsub("LL", "")
    print(str)
  end
end
0