結果

問題 No.225 文字列変更(medium)
ユーザー どん(Don)🇺🇸どん(Don)🇺🇸
提出日時 2023-06-18 13:01:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 138 ms / 5,000 ms
コード長 495 bytes
コンパイル時間 738 ms
コンパイル使用メモリ 87,184 KB
実行使用メモリ 84,648 KB
最終ジャッジ日時 2023-09-08 08:52:44
合計ジャッジ時間 4,931 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 106 ms
79,700 KB
testcase_01 AC 119 ms
81,872 KB
testcase_02 AC 73 ms
71,436 KB
testcase_03 AC 72 ms
71,452 KB
testcase_04 AC 75 ms
70,992 KB
testcase_05 AC 75 ms
71,312 KB
testcase_06 AC 76 ms
71,280 KB
testcase_07 AC 74 ms
71,136 KB
testcase_08 AC 73 ms
71,444 KB
testcase_09 AC 74 ms
71,304 KB
testcase_10 AC 77 ms
70,996 KB
testcase_11 AC 74 ms
70,988 KB
testcase_12 AC 136 ms
83,808 KB
testcase_13 AC 137 ms
84,464 KB
testcase_14 AC 137 ms
84,648 KB
testcase_15 AC 129 ms
83,732 KB
testcase_16 AC 134 ms
83,836 KB
testcase_17 AC 134 ms
83,828 KB
testcase_18 AC 136 ms
83,744 KB
testcase_19 AC 136 ms
83,660 KB
testcase_20 AC 135 ms
83,728 KB
testcase_21 AC 138 ms
84,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
A=input()
B=input()

INF=2**60
dp=[[INF]*(M+1) for i in range(N+1)]
#print(dp)

for i in range(N+1):
    dp[i][0]=i
for j in range(M+1):
    dp[0][j]=j
for i in range(N):
    for j in range(M):
        #置換
        dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+(0 if A[i]==B[j] else 1))
        #削除A
        dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j+1]+1)
        #削除B
        dp[i+1][j+1]=min(dp[i+1][j+1],dp[i+1][j]+1)
        
        #print(dp)


print(dp[N][M])
0