結果

問題 No.225 文字列変更(medium)
ユーザー ffutureffuture
提出日時 2020-09-26 22:09:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 871 ms / 5,000 ms
コード長 691 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 39,952 KB
最終ジャッジ日時 2023-09-12 09:32:01
合計ジャッジ時間 10,324 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 352 ms
19,748 KB
testcase_01 AC 580 ms
29,860 KB
testcase_02 AC 16 ms
7,784 KB
testcase_03 AC 15 ms
7,828 KB
testcase_04 AC 16 ms
7,840 KB
testcase_05 AC 15 ms
7,876 KB
testcase_06 AC 16 ms
7,924 KB
testcase_07 AC 15 ms
7,820 KB
testcase_08 AC 15 ms
7,868 KB
testcase_09 AC 15 ms
7,840 KB
testcase_10 AC 16 ms
7,860 KB
testcase_11 AC 16 ms
7,908 KB
testcase_12 AC 755 ms
33,424 KB
testcase_13 AC 871 ms
39,952 KB
testcase_14 AC 806 ms
38,264 KB
testcase_15 AC 654 ms
23,532 KB
testcase_16 AC 782 ms
37,268 KB
testcase_17 AC 644 ms
23,552 KB
testcase_18 AC 684 ms
28,432 KB
testcase_19 AC 794 ms
37,868 KB
testcase_20 AC 688 ms
30,592 KB
testcase_21 AC 770 ms
36,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def min(a,b,c):
    if a>b:
        if b>c:
            return c
        else:
            return b
    else:
        if a>c:
            return c
        else:
            return a

n,m = map(int,input().split())
S=input()
T=input()
inf=float('inf')
a=[]
for i in range(0,n+1):
    a.append([inf]*(m+1))
a[0][0]=0
for i in range(0,n+1):
    for j in range(0,m+1):
        if j==0 and i==0:
            continue
        elif j==0:
            a[i][j]=a[i-1][j]+1
        elif i==0:
            a[i][j]=a[i][j-1]+1
        else:
            if S[i-1]==T[j-1]:
                a[i][j]=a[i-1][j-1]
            else:
                a[i][j]=min(a[i][j-1],a[i-1][j],a[i-1][j-1])+1

print(a[n][m])
0