結果

問題 No.225 文字列変更(medium)
ユーザー CsTarepandaCsTarepanda
提出日時 2019-07-01 09:05:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 127 ms / 5,000 ms
コード長 887 bytes
コンパイル時間 331 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 84,428 KB
最終ジャッジ日時 2023-09-22 14:19:32
合計ジャッジ時間 3,731 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
79,796 KB
testcase_01 AC 111 ms
81,932 KB
testcase_02 AC 76 ms
71,284 KB
testcase_03 AC 73 ms
71,244 KB
testcase_04 AC 73 ms
71,376 KB
testcase_05 AC 73 ms
71,336 KB
testcase_06 AC 74 ms
71,256 KB
testcase_07 AC 74 ms
71,136 KB
testcase_08 AC 72 ms
71,356 KB
testcase_09 AC 74 ms
71,132 KB
testcase_10 AC 73 ms
71,380 KB
testcase_11 AC 73 ms
71,448 KB
testcase_12 AC 123 ms
83,748 KB
testcase_13 AC 120 ms
84,356 KB
testcase_14 AC 121 ms
84,408 KB
testcase_15 AC 125 ms
83,968 KB
testcase_16 AC 121 ms
84,148 KB
testcase_17 AC 127 ms
84,428 KB
testcase_18 AC 124 ms
83,880 KB
testcase_19 AC 119 ms
83,952 KB
testcase_20 AC 121 ms
83,564 KB
testcase_21 AC 123 ms
83,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
slen, tlen = map(int, input().split())
s = input()
t = input()

# dp = [[None] * tlen for _ in range(slen)]
# def dfs(a=slen - 1, b=tlen - 1):
#     if a == b == -1:
#         return 0
#     if a == -1:
#         return b + 1
#     if b == -1:
#         return a + 1
#
#     if dp[a][b] is not None:
#         return dp[a][b]
#     r = min(
#         dfs(a - 1, b) + 1,
#         dfs(a, b - 1) + 1,
#         dfs(a - 1, b - 1) + (s[a] != t[b]),
#     )
#     dp[a][b] = r
#     return r
# print(dfs())

dp = [[0] * (tlen + 1) for _ in range(slen + 1)]
for b in range(tlen):
    dp[-1][b] = b + 1

for a in range(slen):
    dp[a][-1] = a + 1

for a in range(slen):
    for b in range(tlen):
        dp[a][b] = min(
            dp[a - 1][b] + 1,
            dp[a][b - 1] + 1,
            dp[a - 1][b - 1] + (s[a] != t[b]),
        )
print(dp[a][b])
0