結果

問題 No.225 文字列変更(medium)
ユーザー OttyLabOttyLab
提出日時 2021-08-01 22:59:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 146 ms / 5,000 ms
コード長 502 bytes
コンパイル時間 409 ms
コンパイル使用メモリ 87,104 KB
実行使用メモリ 84,644 KB
最終ジャッジ日時 2023-10-14 19:05:01
合計ジャッジ時間 4,309 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
79,872 KB
testcase_01 AC 131 ms
82,276 KB
testcase_02 AC 71 ms
71,200 KB
testcase_03 AC 70 ms
71,236 KB
testcase_04 AC 70 ms
70,760 KB
testcase_05 AC 69 ms
70,920 KB
testcase_06 AC 70 ms
71,140 KB
testcase_07 AC 69 ms
71,060 KB
testcase_08 AC 70 ms
71,036 KB
testcase_09 AC 69 ms
71,236 KB
testcase_10 AC 72 ms
71,060 KB
testcase_11 AC 70 ms
71,316 KB
testcase_12 AC 144 ms
84,048 KB
testcase_13 AC 142 ms
84,644 KB
testcase_14 AC 138 ms
84,128 KB
testcase_15 AC 142 ms
83,720 KB
testcase_16 AC 145 ms
84,380 KB
testcase_17 AC 146 ms
84,172 KB
testcase_18 AC 145 ms
84,056 KB
testcase_19 AC 140 ms
84,172 KB
testcase_20 AC 146 ms
83,816 KB
testcase_21 AC 143 ms
84,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

INF = 10**10
DP = []
for _ in range(N+2):
    DP.append([INF]*(M+2))
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)

        DP[i+1][j] = min(DP[i][j] + 1, DP[i+1][j])
        DP[i][j+1] = min(DP[i][j] + 1, DP[i][j+1])
print(DP[N][M])
0