結果

問題 No.225 文字列変更(medium)
ユーザー 👑 obakyanobakyan
提出日時 2020-12-13 22:57:35
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 28 ms / 5,000 ms
コード長 894 bytes
コンパイル時間 465 ms
コンパイル使用メモリ 5,332 KB
実行使用メモリ 11,204 KB
最終ジャッジ日時 2023-10-20 04:31:02
合計ジャッジ時間 1,816 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
5,836 KB
testcase_01 AC 19 ms
11,204 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 2 ms
4,368 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 1 ms
4,368 KB
testcase_09 AC 2 ms
4,368 KB
testcase_10 AC 2 ms
4,368 KB
testcase_11 AC 2 ms
4,368 KB
testcase_12 AC 22 ms
10,416 KB
testcase_13 AC 22 ms
10,976 KB
testcase_14 AC 22 ms
10,924 KB
testcase_15 AC 26 ms
10,544 KB
testcase_16 AC 22 ms
10,992 KB
testcase_17 AC 27 ms
10,456 KB
testcase_18 AC 28 ms
10,352 KB
testcase_19 AC 22 ms
10,744 KB
testcase_20 AC 22 ms
10,400 KB
testcase_21 AC 22 ms
10,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
local n, m = io.read("*n", "*n", "*l")
local str = io.read()
local a = {}
for i = 1, n do
  a[i] = str:byte(i)
end
str = io.read()
local b = {}
for i = 1, m do
  b[i] = str:byte(i)
end
local inf = 1000000007
local t = {}
for i = 1, n + 1 do
  t[i] = {}
  for j = 1, m + 1 do
    t[i][j] = inf
  end
end
t[1][1] = 0
for i = 1, n + 1 do
  local num_i = a[i]
  for j = 1, m + 1 do
    local tij = t[i][j]
    local num_j = b[j]
    if j < m + 1 then
      t[i][j + 1] = mmi(t[i][j + 1], 1 + tij)
    end
    if i < n + 1 then
      t[i + 1][j] = mmi(t[i + 1][j], 1 + tij)
    end
    if j < m + 1 and i < n + 1 then
      local cost = 1
      if num_i and num_i == num_j then
        cost = 0
      end
      t[i + 1][j + 1] = mmi(t[i + 1][j + 1], cost + tij)
    end
  end
end
for i = 1, n + 1 do
  -- print(table.concat(t[i], " "))
end
print(t[n + 1][m + 1])
0