結果
問題 | No.225 文字列変更(medium) |
ユーザー |
👑 |
提出日時 | 2020-12-13 22:57:35 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 26 ms / 5,000 ms |
コード長 | 894 bytes |
コンパイル時間 | 254 ms |
コンパイル使用メモリ | 6,816 KB |
実行使用メモリ | 11,136 KB |
最終ジャッジ日時 | 2024-09-20 00:15:23 |
合計ジャッジ時間 | 1,196 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
local mmi, mma = math.min, math.maxlocal n, m = io.read("*n", "*n", "*l")local str = io.read()local a = {}for i = 1, n doa[i] = str:byte(i)endstr = io.read()local b = {}for i = 1, m dob[i] = str:byte(i)endlocal inf = 1000000007local t = {}for i = 1, n + 1 dot[i] = {}for j = 1, m + 1 dot[i][j] = infendendt[1][1] = 0for i = 1, n + 1 dolocal num_i = a[i]for j = 1, m + 1 dolocal tij = t[i][j]local num_j = b[j]if j < m + 1 thent[i][j + 1] = mmi(t[i][j + 1], 1 + tij)endif i < n + 1 thent[i + 1][j] = mmi(t[i + 1][j], 1 + tij)endif j < m + 1 and i < n + 1 thenlocal cost = 1if num_i and num_i == num_j thencost = 0endt[i + 1][j + 1] = mmi(t[i + 1][j + 1], cost + tij)endendendfor i = 1, n + 1 do-- print(table.concat(t[i], " "))endprint(t[n + 1][m + 1])