結果

問題 No.1512 作文
ユーザー 👑 obakyanobakyan
提出日時 2021-05-24 00:25:13
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,018 bytes
コンパイル時間 58 ms
コンパイル使用メモリ 6,812 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 09:26:33
合計ジャッジ時間 1,630 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

local mmi, mma = math.min, math.max
local n = io.read("*n", "*l")
local lp = {}
for i = 1, 26 do
  lp[i] = 0
end
local nodeval = {}
local edge = {}
for i = 1, 26 do
  nodeval[i] = 0
  edge[i] = {}
end
for i = 1, n do
  local s = io.read()
  local sn = #s
  local valid = true
  for j = 1, sn - 1 do
    if s:sub(j + 1, j + 1) < s:sub(j, j) then
      valid = false
      break
    end
  end
  if valid then
    local spos = s:byte(1) - 96
    local tpos = s:byte(#s) - 96
    if spos == tpos then
      lp[spos] = lp[spos] + #s
      for dst = tpos + 1, 26 do
        if not edge[spos][dst] then
          edge[spos][dst] = 0
        end
      end
    else
      for dst = tpos, 26 do
        if not edge[spos][dst] or edge[spos][dst] < #s then
          edge[spos][dst] = #s
        end
      end
    end
  end
end
local ret = 0
for src = 1, 26 do
  ret = mma(ret, nodeval[src] + lp[src])
  for dst, cost in pairs(edge[src]) do
    nodeval[dst] = mma(nodeval[dst], nodeval[src] + lp[src] + cost)
  end
end
print(ret)
0