結果

問題 No.225 文字列変更(medium)
ユーザー k-kk-k
提出日時 2019-11-15 15:41:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,040 ms / 5,000 ms
コード長 432 bytes
コンパイル時間 424 ms
コンパイル使用メモリ 11,764 KB
実行使用メモリ 43,604 KB
最終ジャッジ日時 2023-10-25 03:35:59
合計ジャッジ時間 13,174 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 401 ms
21,884 KB
testcase_01 AC 704 ms
31,896 KB
testcase_02 AC 29 ms
10,064 KB
testcase_03 AC 29 ms
10,060 KB
testcase_04 AC 28 ms
10,064 KB
testcase_05 AC 29 ms
10,060 KB
testcase_06 AC 29 ms
10,064 KB
testcase_07 AC 29 ms
10,064 KB
testcase_08 AC 28 ms
10,060 KB
testcase_09 AC 29 ms
10,064 KB
testcase_10 AC 29 ms
10,060 KB
testcase_11 AC 29 ms
10,064 KB
testcase_12 AC 959 ms
37,776 KB
testcase_13 AC 1,040 ms
43,604 KB
testcase_14 AC 1,003 ms
41,208 KB
testcase_15 AC 960 ms
32,760 KB
testcase_16 AC 976 ms
40,676 KB
testcase_17 AC 973 ms
33,812 KB
testcase_18 AC 935 ms
35,136 KB
testcase_19 AC 974 ms
40,680 KB
testcase_20 AC 923 ms
35,928 KB
testcase_21 AC 980 ms
39,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split(' '))
S = input()
T = input()
# n * mの配列を作成
d = [[None for i in range(m+1)] for j in range(n+1)]

d[0] = list(range(m + 1))

for i in range(1, n + 1):
    d[i][0] = i 
    for j in range(1, m + 1):
        if S[i-1] == T[j-1]:
            d[i][j] = min(d[i][j-1] + 1, d[i-1][j] + 1, d[i-1][j-1])
        else:
            d[i][j] = min(d[i][j-1], d[i-1][j], d[i-1][j-1]) + 1

print(d[n][m])
0