結果

問題 No.225 文字列変更(medium)
ユーザー ckawatakckawatak
提出日時 2019-03-30 18:10:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 103 ms / 5,000 ms
コード長 404 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 82,140 KB
実行使用メモリ 83,948 KB
最終ジャッジ日時 2024-04-27 17:10:44
合計ジャッジ時間 2,564 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
78,836 KB
testcase_01 AC 85 ms
80,632 KB
testcase_02 AC 38 ms
52,648 KB
testcase_03 AC 37 ms
52,468 KB
testcase_04 AC 39 ms
52,220 KB
testcase_05 AC 38 ms
52,028 KB
testcase_06 AC 38 ms
53,112 KB
testcase_07 AC 39 ms
52,396 KB
testcase_08 AC 39 ms
52,636 KB
testcase_09 AC 38 ms
52,556 KB
testcase_10 AC 39 ms
54,168 KB
testcase_11 AC 38 ms
52,488 KB
testcase_12 AC 102 ms
82,856 KB
testcase_13 AC 101 ms
83,948 KB
testcase_14 AC 98 ms
83,320 KB
testcase_15 AC 100 ms
82,388 KB
testcase_16 AC 101 ms
83,080 KB
testcase_17 AC 103 ms
83,000 KB
testcase_18 AC 102 ms
82,208 KB
testcase_19 AC 98 ms
83,192 KB
testcase_20 AC 99 ms
82,060 KB
testcase_21 AC 101 ms
82,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

dp = []
for _ in range(N+1):
    dp.append([0 for _ in range(M+1)])

for i in range(N+1):
    dp[i][0] = i
    
for j in range(M+1):
    dp[0][j] = j

for i in range(1,N+1):
    for j in range(1,M+1):
        cost = 0 if S[i-1] == T[j-1] else 1
        dp[i][j] = min(dp[i-1][j] + 1, dp[i][j-1] + 1, dp[i-1][j-1] + cost)

print(dp[N][M])
0