結果

問題 No.225 文字列変更(medium)
ユーザー 👑 H20H20
提出日時 2021-06-29 13:53:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 140 ms / 5,000 ms
コード長 485 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 87,244 KB
実行使用メモリ 84,932 KB
最終ジャッジ日時 2023-09-08 00:14:43
合計ジャッジ時間 3,582 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
79,984 KB
testcase_01 AC 120 ms
82,416 KB
testcase_02 AC 68 ms
71,568 KB
testcase_03 AC 67 ms
71,436 KB
testcase_04 AC 68 ms
71,568 KB
testcase_05 AC 67 ms
71,572 KB
testcase_06 AC 69 ms
71,628 KB
testcase_07 AC 69 ms
71,464 KB
testcase_08 AC 66 ms
71,464 KB
testcase_09 AC 68 ms
71,292 KB
testcase_10 AC 68 ms
71,584 KB
testcase_11 AC 67 ms
71,256 KB
testcase_12 AC 139 ms
84,312 KB
testcase_13 AC 138 ms
84,760 KB
testcase_14 AC 136 ms
84,932 KB
testcase_15 AC 139 ms
84,240 KB
testcase_16 AC 136 ms
84,660 KB
testcase_17 AC 139 ms
84,300 KB
testcase_18 AC 140 ms
84,288 KB
testcase_19 AC 136 ms
84,644 KB
testcase_20 AC 139 ms
84,048 KB
testcase_21 AC 137 ms
84,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
S = input()
T = input()
DP = [[10**5]*(M+1) for _ in range(N+1)]
DP[0][0]=0
for i in range(N+1):
    for j in range(M+1):
        if i<N and j<M :
            if S[i]==T[j]:
                DP[i+1][j+1]=min(DP[i+1][j+1],DP[i][j])
            else:
                DP[i+1][j+1]=min(DP[i+1][j+1],DP[i][j]+1)
        if i<N:
            DP[i+1][j]=min(DP[i+1][j],DP[i][j]+1)
        if j<M:
            DP[i][j+1]=min(DP[i][j+1],DP[i][j]+1)

print(DP[N][M])
0