結果

問題 No.225 文字列変更(medium)
ユーザー lloyzlloyz
提出日時 2023-04-12 21:25:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 550 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 83,456 KB
最終ジャッジ日時 2024-04-17 07:30:41
合計ジャッジ時間 3,214 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
79,104 KB
testcase_01 AC 116 ms
81,152 KB
testcase_02 AC 42 ms
51,712 KB
testcase_03 AC 41 ms
51,456 KB
testcase_04 AC 42 ms
51,840 KB
testcase_05 AC 46 ms
52,480 KB
testcase_06 AC 42 ms
52,352 KB
testcase_07 AC 42 ms
51,840 KB
testcase_08 AC 43 ms
52,224 KB
testcase_09 AC 43 ms
52,352 KB
testcase_10 AC 43 ms
52,480 KB
testcase_11 AC 43 ms
52,352 KB
testcase_12 AC 134 ms
82,944 KB
testcase_13 AC 135 ms
83,456 KB
testcase_14 AC 132 ms
83,200 KB
testcase_15 AC 129 ms
82,432 KB
testcase_16 AC 134 ms
82,816 KB
testcase_17 AC 132 ms
82,560 KB
testcase_18 AC 133 ms
82,432 KB
testcase_19 AC 132 ms
82,688 KB
testcase_20 AC 132 ms
82,048 KB
testcase_21 AC 135 ms
83,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
s = input()
t = input()
INF = 10**18

DP = [[INF for _ in range(m + 1)] for _ in range(n + 1)]
DP[0][0] = 0
for i in range(n):
    for j in range(m):
        DP[i + 1][j] = min(DP[i + 1][j], DP[i][j] + 1)
        DP[i][j + 1] = min(DP[i][j + 1], DP[i][j] + 1)
        if s[i] == t[j]:
            DP[i + 1][j + 1] = min(DP[i + 1][j + 1], DP[i][j], DP[i + 1][j] + 1, DP[i][j + 1] + 1)
        else:
            DP[i + 1][j + 1] = min(DP[i + 1][j + 1], DP[i][j] + 1, DP[i + 1][j] + 1, DP[i][j + 1] + 1)
print(DP[n][m])
0