結果

問題 No.225 文字列変更(medium)
ユーザー OttyLabOttyLab
提出日時 2021-08-01 23:53:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 139 ms / 5,000 ms
コード長 548 bytes
コンパイル時間 551 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 84,616 KB
最終ジャッジ日時 2023-10-14 19:05:44
合計ジャッジ時間 3,799 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
79,716 KB
testcase_01 AC 121 ms
81,944 KB
testcase_02 AC 70 ms
71,288 KB
testcase_03 AC 69 ms
71,288 KB
testcase_04 AC 67 ms
70,812 KB
testcase_05 AC 70 ms
71,284 KB
testcase_06 AC 68 ms
71,072 KB
testcase_07 AC 68 ms
71,060 KB
testcase_08 AC 68 ms
71,148 KB
testcase_09 AC 71 ms
71,348 KB
testcase_10 AC 70 ms
70,996 KB
testcase_11 AC 67 ms
71,040 KB
testcase_12 AC 133 ms
84,260 KB
testcase_13 AC 132 ms
84,616 KB
testcase_14 AC 136 ms
84,460 KB
testcase_15 AC 138 ms
83,928 KB
testcase_16 AC 134 ms
84,156 KB
testcase_17 AC 136 ms
84,260 KB
testcase_18 AC 138 ms
83,728 KB
testcase_19 AC 139 ms
83,764 KB
testcase_20 AC 134 ms
83,936 KB
testcase_21 AC 132 ms
84,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
S = ' ' + input()
T = ' ' + input()

INF = 10**10
DP = []
for _ in range(N+1):
    DP.append([INF]*(M+1))
DP[0][0] = 0 

for i in range(N+1):
    for j in range(M+1):
        if i > 0 and j > 0:
            if S[i] == T[j]:
                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-1][j] + 1, DP[i][j])
        if j > 0:
            DP[i][j] = min(DP[i][j-1] + 1, DP[i][j])

print(DP[N][M])
0