結果

問題 No.225 文字列変更(medium)
ユーザー damindamin
提出日時 2020-02-15 16:00:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 755 ms / 5,000 ms
コード長 762 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 43,392 KB
最終ジャッジ日時 2024-04-16 03:13:29
合計ジャッジ時間 9,596 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 293 ms
22,528 KB
testcase_01 AC 494 ms
32,512 KB
testcase_02 AC 31 ms
10,752 KB
testcase_03 AC 31 ms
10,880 KB
testcase_04 AC 32 ms
10,880 KB
testcase_05 AC 32 ms
10,752 KB
testcase_06 AC 31 ms
10,880 KB
testcase_07 AC 31 ms
10,880 KB
testcase_08 AC 31 ms
10,880 KB
testcase_09 AC 32 ms
10,752 KB
testcase_10 AC 32 ms
10,752 KB
testcase_11 AC 31 ms
10,880 KB
testcase_12 AC 676 ms
35,840 KB
testcase_13 AC 755 ms
43,392 KB
testcase_14 AC 728 ms
40,832 KB
testcase_15 AC 659 ms
26,112 KB
testcase_16 AC 697 ms
40,320 KB
testcase_17 AC 665 ms
27,008 KB
testcase_18 AC 652 ms
30,976 KB
testcase_19 AC 710 ms
40,448 KB
testcase_20 AC 753 ms
33,280 KB
testcase_21 AC 688 ms
39,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Levenshtein_dist(S,T):
    s=len(S)
    t=len(T)
    dp=[[1145141919810931 for i in range(t+1)] for j in range(s+1)]
    dp[0][0]=0

    for i in range(-1,s):
        for j in range(-1,t):
            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[s][t]

  
_,_=map(int,input().split())
S=input()
T=input()
print(Levenshtein_dist(S,T))
0