結果

問題 No.225 文字列変更(medium)
ユーザー AT274_AT274_
提出日時 2018-08-13 21:28:30
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,042 ms / 5,000 ms
コード長 369 bytes
コンパイル時間 588 ms
コンパイル使用メモリ 11,784 KB
実行使用メモリ 44,224 KB
最終ジャッジ日時 2023-10-24 16:50:06
合計ジャッジ時間 12,405 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 423 ms
21,792 KB
testcase_01 AC 688 ms
32,248 KB
testcase_02 AC 28 ms
10,088 KB
testcase_03 AC 26 ms
10,088 KB
testcase_04 AC 27 ms
10,092 KB
testcase_05 AC 27 ms
10,088 KB
testcase_06 AC 27 ms
10,088 KB
testcase_07 AC 26 ms
10,088 KB
testcase_08 AC 27 ms
10,088 KB
testcase_09 AC 27 ms
10,088 KB
testcase_10 AC 27 ms
10,092 KB
testcase_11 AC 27 ms
10,092 KB
testcase_12 AC 977 ms
39,708 KB
testcase_13 AC 1,042 ms
44,224 KB
testcase_14 AC 1,002 ms
42,856 KB
testcase_15 AC 979 ms
33,516 KB
testcase_16 AC 987 ms
41,872 KB
testcase_17 AC 962 ms
33,408 KB
testcase_18 AC 950 ms
37,024 KB
testcase_19 AC 970 ms
41,876 KB
testcase_20 AC 941 ms
37,680 KB
testcase_21 AC 977 ms
41,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
S = input()
T = input()

dp = [[float('inf')] * (N + 1) for i in range(M + 1)]

# 初期化
for i in range(M + 1):
    dp[i][0] = i
for j in range(N + 1):
    dp[0][j] = j

for i in range(1, M + 1):
    for j in range(1, N + 1):
        dp[i][j] = min(dp[i-1][j-1] + (S[j-1] != T[i-1]), dp[i-1][j] + 1, dp[i][j-1] + 1)

print(dp[M][N])
0