結果

問題 No.225 文字列変更(medium)
ユーザー Kaito KoikeKaito Koike
提出日時 2018-05-20 12:14:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 775 bytes
コンパイル時間 117 ms
コンパイル使用メモリ 10,804 KB
実行使用メモリ 63,076 KB
最終ジャッジ日時 2023-09-10 23:58:08
合計ジャッジ時間 28,408 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 899 ms
41,092 KB
testcase_01 AC 1,477 ms
51,620 KB
testcase_02 AC 131 ms
29,568 KB
testcase_03 AC 131 ms
29,548 KB
testcase_04 AC 131 ms
29,508 KB
testcase_05 WA -
testcase_06 AC 131 ms
29,444 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 130 ms
29,524 KB
testcase_10 AC 132 ms
29,496 KB
testcase_11 AC 129 ms
29,504 KB
testcase_12 AC 1,973 ms
57,640 KB
testcase_13 WA -
testcase_14 AC 2,088 ms
60,524 KB
testcase_15 AC 1,950 ms
52,424 KB
testcase_16 AC 1,993 ms
60,796 KB
testcase_17 AC 1,975 ms
52,800 KB
testcase_18 AC 1,902 ms
55,216 KB
testcase_19 AC 2,033 ms
60,016 KB
testcase_20 WA -
testcase_21 AC 2,027 ms
59,184 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
n,m = map(int,input().split())

S = list(input())
T = list(input())

dp = [[987654321 for i in range(len(S)+1)] for j in range(len(T)+1)]
dp[0][0] = 0

"""
#変更
if S[i] == T[j]:
    dp[j+1][i+1] = dp[j][i]
else:
    dp[j+1][i+1] = dp[j][i] + 1

#削除
dp[j+1][i+1] = dp[j+1][i] + 1

#挿入
dp[j+1][i+1] = dp[j][i+1] + 1
"""

for i in range(len(S)):
    for j in range(len(T)):
        if i >=0 and j >= 0:
            if S[i]== T[j]:
                dp[j+1][i+1] = min(dp[j][i],dp[j+1][i+1])
            else:
                dp[j+1][i+1] = min(dp[j][i]+1,dp[j+1][i+1])
        if i >= 0:
            dp[j+1][i+1] = min(dp[j+1][i]+1,dp[j+1][i+1])
        if j >= 0:
            dp[j+1][i+1] = min(dp[j][i+1]+1,dp[j+1][i+1])

print(dp[len(T)][len(S)])
0