結果

問題 No.225 文字列変更(medium)
ユーザー NatsubiSoganNatsubiSogan
提出日時 2020-10-04 12:08:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 152 ms / 5,000 ms
コード長 586 bytes
コンパイル時間 829 ms
コンパイル使用メモリ 86,968 KB
実行使用メモリ 88,548 KB
最終ジャッジ日時 2023-09-26 13:36:25
合計ジャッジ時間 4,618 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
80,228 KB
testcase_01 AC 134 ms
86,380 KB
testcase_02 AC 74 ms
71,304 KB
testcase_03 AC 74 ms
71,492 KB
testcase_04 AC 77 ms
71,312 KB
testcase_05 AC 76 ms
71,204 KB
testcase_06 AC 76 ms
71,288 KB
testcase_07 AC 73 ms
71,508 KB
testcase_08 AC 74 ms
71,376 KB
testcase_09 AC 74 ms
71,208 KB
testcase_10 AC 74 ms
71,504 KB
testcase_11 AC 74 ms
71,532 KB
testcase_12 AC 152 ms
87,776 KB
testcase_13 AC 147 ms
88,500 KB
testcase_14 AC 151 ms
88,232 KB
testcase_15 AC 149 ms
88,084 KB
testcase_16 AC 145 ms
88,548 KB
testcase_17 AC 150 ms
87,904 KB
testcase_18 AC 149 ms
87,892 KB
testcase_19 AC 145 ms
88,408 KB
testcase_20 AC 148 ms
87,884 KB
testcase_21 AC 147 ms
87,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
s = input()
t = input()
dp = [[float("inf")] * (m + 1) for i in range(n + 1)]
dp[0][0] = 0
for i in range(n + 1):
    for j in range(m + 1):
        if i == j == -1:
            continue
        if i > 0 and j > 0:
            if s[i - 1] == t[j - 1]:
                dp[i][j] = min(dp[i][j], dp[i - 1][j - 1])
            else:
                dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1)
        if i > 0:
            dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1)
        if j > 0:
            dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1)
print(dp[n][m])
0