結果

問題 No.859 路線A、路線B、路線C
ユーザー 👑 obakyanobakyan
提出日時 2019-08-15 17:48:17
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 1,216 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 5,152 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 19:13:12
合計ジャッジ時間 1,425 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local a, b, c = io.read("*n", "*n", "*n", "*l")
local str = io.read()
local start_type, start_idx = str:match("(%w) (%d+)")
start_idx = tonumber(start_idx)
str = io.read()
local end_type, end_idx = str:match("(%w) (%d+)")
end_idx = tonumber(end_idx)
local edge = {}
local function add(i1, i2, c)
  table.insert(edge, {i1, i2, c})
  table.insert(edge, {i2, i1, c})
end
add(1, 2, a - 1)
add(3, 4, b - 1)
add(5, 6, c - 1)
add(1, 3, 1)
add(1, 5, 1)
add(3, 5, 1)
add(2, 4, 1)
add(2, 6, 1)
add(4, 6, 1)
if start_type == "A" then
  add(7, 1, start_idx - 1)
  add(7, 2, a - start_idx)
elseif start_type == "B" then
  add(7, 3, start_idx - 1)
  add(7, 4, b - start_idx)
else
  add(7, 5, start_idx - 1)
  add(7, 6, c - start_idx)
end

if end_type == "A" then
  add(8, 1, end_idx - 1)
  add(8, 2, a - end_idx)
elseif end_type == "B" then
  add(8, 3, end_idx - 1)
  add(8, 4, b - end_idx)
else
  add(8, 5, end_idx - 1)
  add(8, 6, c - end_idx)
end

local len = {}
local inf = 10000000000
for i = 1, 8 do len[i] = inf end
len[7] = 0
for i = 1, 10 do
  for j = 1, #edge do
    local src, dst, c = edge[j][1], edge[j][2], edge[j][3]
    if len[src] + c < len[dst] then
      len[dst] = len[src] + c
    end
  end
end
print(len[8])
0