結果
問題 | No.225 文字列変更(medium) |
ユーザー |
![]() |
提出日時 | 2020-02-15 15:20:30 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 737 ms / 5,000 ms |
コード長 | 625 bytes |
コンパイル時間 | 285 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 43,008 KB |
最終ジャッジ日時 | 2024-10-06 13:54:38 |
合計ジャッジ時間 | 9,496 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 22 |
ソースコード
def Levenshtein_dist(S,T): m=len(S) n=len(T) inf=float("inf") dp=[[inf for i in range(n+1)] for j in range(m+1)] dp[0][0]=0 for i in range(-1,m): for j in range(-1,n): if i==-1 and j==-1: continue elif i>=0 and j>=0: if S[i]==T[j]: dp[i+1][j+1]=min(dp[i][j],dp[i][j+1]+1, dp[i+1][j]+1) else: dp[i+1][j+1]=min(dp[i][j]+1,dp[i][j+1]+1, dp[i+1][j]+1) elif i>=0: dp[i+1][j+1] = dp[i][j+1]+1 elif j>=0: dp[i+1][j+1] = dp[i+1][j]+1 return dp[m][n] s,t=map(int,input().split()) S=input() T=input() print(Levenshtein_dist(S,T))