結果
| 問題 | No.30 たこやき工場 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-05-03 10:32:53 |
| 言語 | Lua (LuaJit 2.1.1765228720) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,046 bytes |
| 記録 | |
| コンパイル時間 | 411 ms |
| コンパイル使用メモリ | 6,816 KB |
| 実行使用メモリ | 9,632 KB |
| 最終ジャッジ日時 | 2024-12-31 15:30:13 |
| 合計ジャッジ時間 | 7,283 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 TLE * 1 |
ソースコード
local ior = io.input()
local n, m = ior:read("*n", "*n")
local r_to_p = {}
local buycount = {}
for i = 1, n do
r_to_p[i] = {}
buycount[i] = 0
end
for i = 1, m do
local p, q, r = ior:read("*n", "*n", "*n")
local tmp = {}
tmp.p = p
tmp.cnt = q
table.insert(r_to_p[r], tmp)
end
local tasks = {}
for i = 1, n - 1 do tasks[i] = 0 end
tasks[n] = 1
local taskidxs = {}
taskidxs[n] = true
while(true) do
local taskidx, unused = next(taskidxs)
if(taskidx == nil) then break end
local cur_cnt = tasks[taskidx]
if(#r_to_p[taskidx] == 0) then
buycount[taskidx] = buycount[taskidx] + cur_cnt
else
local m = #r_to_p[taskidx]
for i = 1, m do
local nextdst = r_to_p[taskidx][i].p
if(taskidxs[nextdst] == nil) then
taskidxs[nextdst] = true
tasks[nextdst] = r_to_p[taskidx][i].cnt * cur_cnt
else
tasks[nextdst] = tasks[nextdst] + r_to_p[taskidx][i].cnt * cur_cnt
end
end
end
taskidxs[taskidx] = nil
tasks[taskidx] = 0
end
for i = 1, n - 1 do
print(buycount[i])
end