結果
| 問題 |
No.859 路線A、路線B、路線C
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2019-08-15 17:49:15 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,294 bytes |
| コンパイル時間 | 117 ms |
| コンパイル使用メモリ | 5,376 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-19 15:27:13 |
| 合計ジャッジ時間 | 605 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
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
if start_type == end_type then
add(7, 8, math.abs(start_idx - 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])