結果

問題 No.225 文字列変更(medium)
ユーザー brthyyjpbrthyyjp
提出日時 2020-09-22 11:42:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 140 ms / 5,000 ms
コード長 606 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 86,948 KB
実行使用メモリ 84,944 KB
最終ジャッジ日時 2023-09-08 05:44:48
合計ジャッジ時間 4,076 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
84,848 KB
testcase_01 AC 125 ms
84,576 KB
testcase_02 AC 73 ms
71,012 KB
testcase_03 AC 75 ms
70,884 KB
testcase_04 AC 74 ms
70,876 KB
testcase_05 AC 75 ms
71,032 KB
testcase_06 AC 75 ms
71,088 KB
testcase_07 AC 73 ms
71,012 KB
testcase_08 AC 75 ms
71,172 KB
testcase_09 AC 77 ms
70,976 KB
testcase_10 AC 75 ms
71,136 KB
testcase_11 AC 75 ms
71,004 KB
testcase_12 AC 139 ms
84,832 KB
testcase_13 AC 133 ms
84,852 KB
testcase_14 AC 136 ms
84,876 KB
testcase_15 AC 137 ms
84,864 KB
testcase_16 AC 134 ms
84,876 KB
testcase_17 AC 140 ms
84,944 KB
testcase_18 AC 134 ms
84,936 KB
testcase_19 AC 132 ms
84,900 KB
testcase_20 AC 136 ms
84,644 KB
testcase_21 AC 133 ms
84,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
s = str(input())
t = str(input())

INF = 10**18
dp = [[INF]*1010 for _ in range(1010)]
dp[0][0] = 0

for i in range(-1, n):
    for j in range(-1, m):
        if i == -1 and j == -1:
            continue
        if i >= 0 and j >= 0:
            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 >= 0:
            dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j+1]+1)
        if j >= 0:
            dp[i+1][j+1] = min(dp[i+1][j+1], dp[i+1][j]+1)
print(dp[n][m])
0