結果

問題 No.225 文字列変更(medium)
ユーザー roarisroaris
提出日時 2020-07-29 22:59:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 123 ms / 5,000 ms
コード長 471 bytes
コンパイル時間 554 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 84,480 KB
最終ジャッジ日時 2023-09-13 01:25:47
合計ジャッジ時間 4,116 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
79,828 KB
testcase_01 AC 109 ms
82,064 KB
testcase_02 AC 70 ms
71,388 KB
testcase_03 AC 70 ms
71,116 KB
testcase_04 AC 70 ms
71,408 KB
testcase_05 AC 71 ms
71,068 KB
testcase_06 AC 70 ms
71,184 KB
testcase_07 AC 71 ms
71,520 KB
testcase_08 AC 70 ms
71,584 KB
testcase_09 AC 69 ms
71,436 KB
testcase_10 AC 68 ms
71,244 KB
testcase_11 AC 70 ms
71,436 KB
testcase_12 AC 121 ms
84,300 KB
testcase_13 AC 119 ms
84,480 KB
testcase_14 AC 123 ms
84,412 KB
testcase_15 AC 114 ms
83,676 KB
testcase_16 AC 119 ms
84,116 KB
testcase_17 AC 116 ms
83,888 KB
testcase_18 AC 117 ms
83,936 KB
testcase_19 AC 117 ms
84,064 KB
testcase_20 AC 117 ms
83,712 KB
testcase_21 AC 117 ms
84,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

n, m = map(int, input().split())
S = input()[:-1]
T = input()[:-1]
dp = [[0]*(m+1) for _ in range(n+1)]

for i in range(n+1):
    dp[i][0] = i

for i in range(m+1):
    dp[0][i] = i

for i in range(1, n+1):
    for j in range(1, m+1):
        if S[i-1]==T[j-1]:
            dp[i][j] = min(dp[i-1][j-1], dp[i-1][j]+1, dp[i][j-1]+1)
        else:
            dp[i][j] = min(dp[i-1][j-1]+1, dp[i-1][j]+1, dp[i][j-1]+1)

print(dp[n][m])
0