結果

問題 No.225 文字列変更(medium)
ユーザー damindamin
提出日時 2020-02-15 15:20:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 748 ms / 5,000 ms
コード長 625 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 43,264 KB
最終ジャッジ日時 2024-04-16 03:12:25
合計ジャッジ時間 9,455 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 293 ms
22,400 KB
testcase_01 AC 498 ms
32,512 KB
testcase_02 AC 31 ms
10,624 KB
testcase_03 AC 32 ms
10,624 KB
testcase_04 AC 32 ms
10,624 KB
testcase_05 AC 31 ms
10,752 KB
testcase_06 AC 31 ms
10,624 KB
testcase_07 AC 31 ms
10,624 KB
testcase_08 AC 31 ms
10,624 KB
testcase_09 AC 31 ms
10,752 KB
testcase_10 AC 30 ms
10,752 KB
testcase_11 AC 31 ms
10,752 KB
testcase_12 AC 671 ms
35,712 KB
testcase_13 AC 748 ms
43,264 KB
testcase_14 AC 726 ms
40,448 KB
testcase_15 AC 656 ms
25,856 KB
testcase_16 AC 690 ms
40,320 KB
testcase_17 AC 664 ms
26,880 KB
testcase_18 AC 652 ms
30,976 KB
testcase_19 AC 699 ms
40,448 KB
testcase_20 AC 649 ms
33,152 KB
testcase_21 AC 690 ms
38,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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))
0