結果

問題 No.1512 作文
ユーザー 👑 obakyanobakyan
提出日時 2021-05-24 00:23:39
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 898 bytes
コンパイル時間 36 ms
コンパイル使用メモリ 6,684 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-20 09:25:32
合計ジャッジ時間 2,125 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 23 ms
6,940 KB
testcase_05 AC 25 ms
6,940 KB
testcase_06 AC 26 ms
6,940 KB
testcase_07 AC 25 ms
6,944 KB
testcase_08 AC 28 ms
6,944 KB
testcase_09 AC 2 ms
6,944 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 2 ms
6,944 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 1 ms
6,944 KB
testcase_25 WA -
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 1 ms
6,944 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 1 ms
6,940 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 2 ms
6,940 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 8 ms
6,940 KB
testcase_36 AC 8 ms
6,944 KB
testcase_37 AC 6 ms
6,940 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 25 ms
6,940 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
    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