結果

問題 No.30 たこやき工場
コンテスト
ユーザー obakyan
提出日時 2019-05-03 10:01:36
言語 Lua
(LuaJit 2.1.1774638290)
コンパイル:
luajit -b _filename_ a.out
実行:
luajit _filename_
結果
MLE  
実行時間 -
コード長 887 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 55 ms
コンパイル使用メモリ 8,096 KB
実行使用メモリ 1,305,856 KB
最終ジャッジ日時 2026-06-05 02:51:16
合計ジャッジ時間 3,646 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10 MLE * 2 -- * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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 function maketask(r, count)
  local tmp = {}
  tmp.r = r
  tmp.cnt = count
  return tmp
end

local tasks = {}
local done = 0
local tasknum = 1
tasks[1] = maketask(n, 1)

while(done < tasknum) do
  done = done + 1
  local cur_r = tasks[done].r
  local cur_cnt = tasks[done].cnt
  if(#r_to_p[cur_r] == 0) then
    buycount[cur_r] = buycount[cur_r] + cur_cnt
  else
    local m = #r_to_p[cur_r]
    for i = 1, m do
      table.insert(tasks, maketask(r_to_p[cur_r][i].p, r_to_p[cur_r][i].cnt * cur_cnt))
      tasknum = tasknum + 1
    end
  end
end
for i = 1, n - 1 do
  print(buycount[i])
end
0