結果

問題 No.30 たこやき工場
ユーザー 👑 obakyanobakyan
提出日時 2019-05-03 11:17:17
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,295 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 5,296 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-23 05:21:07
合計ジャッジ時間 959 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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 = {}
for i = 1, n - 1 do taskidxs[i] = false end
taskidxs[n] = true

while(true) do
  local tmp = nil
  for taskidx = 1, n do
    if(taskidxs[taskidx]) then
      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(not taskidxs[nextdst]) 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] = false
      tasks[taskidx] = 0
    end
  end
  local tmp = nil
  for taskidx = 1, n do
    if(taskidxs[taskidx]) then tmp = taskidx end
  end
  if(tmp == nil) then break end
end
for i = 1, n - 1 do
  print(buycount[i])
end
0