結果

問題 No.1029 JJOOII 3
ユーザー 👑 obakyanobakyan
提出日時 2020-04-17 22:19:53
言語 Lua
(LuaJit 2.1.1696795921)
結果
TLE  
実行時間 -
コード長 1,406 bytes
コンパイル時間 331 ms
コンパイル使用メモリ 6,948 KB
実行使用メモリ 70,048 KB
最終ジャッジ日時 2024-04-14 14:35:31
合計ジャッジ時間 5,862 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,760 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1,711 ms
35,840 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
local n, k = io.read("*n", "*n", "*l")
local w, c = {}, {}
for i = 1, n do
  local s = io.read()
  local wi, ci = s:match("(%w+) (%d+)")
  w[i] = wi
  c[i] = tonumber(ci)
end
local t = {}
local edge = {}
for i = 1, k * 3 + 1 do
  edge[i] = {}
  t[i] = -1
end
for i_n = 1, n do
  for j = 1, k * 3 do
    local step = 0
    local need_j = mma(0, k + 1 - j)
    local need_o = mma(0, mmi(k, 2 * k + 1 - j))
    local need_i = mmi(k, 3 * k + 1 - j)
    for i_w = 1, #w[i_n] do
      local ww = w[i_n]:sub(i_w, i_w)
      if 0 < need_j then
        if ww == "J" then
          step = step + 1
          need_j = need_j - 1
        end
      elseif 0 < need_o then
        if ww == "O" then
          step = step + 1
          need_o = need_o - 1
        end
      elseif 0 < need_i then
        if ww == "I" then
          step = step + 1
          need_i = need_i - 1
        end
      end
    end--i_w
    if 0 < step then
      if edge[j][j + step] then
        edge[j][j + step] = mmi(edge[j][j + step], c[i_n])
      else
        edge[j][j + step] = c[i_n]
      end
    end
  end--j
end--i_n
t[1] = 0
for i = 1, 3 * k do
  local srccost = t[i]
  if 0 <= srccost then
    for dst, cost in pairs(edge[i]) do
      if t[dst] == -1 then
        t[dst] = srccost + cost
      else
        t[dst] = mmi(t[dst], srccost + cost)
      end
    end
  end
end
print(t[3 * k + 1])
0