結果

問題 No.225 文字列変更(medium)
ユーザー 👑 KazunKazun
提出日時 2021-02-08 05:07:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 122 ms / 5,000 ms
コード長 667 bytes
コンパイル時間 243 ms
コンパイル使用メモリ 86,880 KB
実行使用メモリ 84,136 KB
最終ジャッジ日時 2023-09-18 08:00:00
合計ジャッジ時間 3,338 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
79,380 KB
testcase_01 AC 110 ms
81,716 KB
testcase_02 AC 72 ms
70,996 KB
testcase_03 AC 71 ms
71,060 KB
testcase_04 AC 69 ms
71,024 KB
testcase_05 AC 70 ms
71,052 KB
testcase_06 AC 71 ms
71,000 KB
testcase_07 AC 70 ms
70,964 KB
testcase_08 AC 69 ms
70,668 KB
testcase_09 AC 71 ms
71,056 KB
testcase_10 AC 70 ms
70,844 KB
testcase_11 AC 69 ms
70,960 KB
testcase_12 AC 122 ms
83,120 KB
testcase_13 AC 113 ms
84,136 KB
testcase_14 AC 113 ms
83,736 KB
testcase_15 AC 120 ms
83,624 KB
testcase_16 AC 113 ms
83,656 KB
testcase_17 AC 120 ms
83,624 KB
testcase_18 AC 120 ms
83,216 KB
testcase_19 AC 111 ms
83,580 KB
testcase_20 AC 117 ms
83,580 KB
testcase_21 AC 113 ms
83,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def Levenshtein_Distance(S:str,T:str,example=False) ->int:
    """文字列S,Tにおけるレーベンシュタイン距離(編集距離) を求める.

    S,T: string
    """
    M=len(S);N=len(T)
    DP=[[0]*(N+1) for _ in range(M+1)]
    DP[0]=list(range(N+1))
    for i in range(1,M+1):
        D=DP[i]
        E=DP[i-1]

        D[0]=i
        for j in range(1,N+1):
            if S[i-1]==T[j-1]:
                D[j]=min(D[j-1]+1,E[j]+1,E[j-1])
            else:
                D[j]=min(D[j-1],E[j],E[j-1])+1

    return D[-1]
#================================================
N,M=map(int,input().split())
S=input()
T=input()
print(Levenshtein_Distance(S,T))
0