結果

問題 No.30 たこやき工場
ユーザー 👑 obakyanobakyan
提出日時 2019-05-03 10:11:50
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 1,073 bytes
コンパイル時間 566 ms
コンパイル使用メモリ 7,036 KB
実行使用メモリ 6,424 KB
最終ジャッジ日時 2023-08-30 05:04:45
合計ジャッジ時間 1,235 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 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 function maketask(r, count)
  local tmp = {}
  tmp.r = r
  tmp.cnt = count
  return tmp
end

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

while(done < tasknum) do
  done = done + 1
  local taskidx = done % tasksize
  if(taskidx == 0) then taskidx = tasksize end
  local cur_r = tasks[taskidx].r
  local cur_cnt = tasks[taskidx].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
      tasknum = tasknum + 1
      local nidx = tasknum % tasksize
      if(nidx == 0) then nidx = tasksize end
      tasks[nidx] = maketask(r_to_p[cur_r][i].p, r_to_p[cur_r][i].cnt * cur_cnt)
    end
  end
end
for i = 1, n - 1 do
  print(buycount[i])
end
0