結果

問題 No.225 文字列変更(medium)
ユーザー HAPPAHAPPA
提出日時 2020-12-14 15:58:16
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 706 ms / 5,000 ms
コード長 615 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 11,944 KB
実行使用メモリ 44,288 KB
最終ジャッジ日時 2023-10-20 05:04:14
合計ジャッジ時間 9,074 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 287 ms
21,948 KB
testcase_01 AC 477 ms
32,372 KB
testcase_02 AC 30 ms
10,176 KB
testcase_03 AC 30 ms
10,172 KB
testcase_04 AC 30 ms
10,172 KB
testcase_05 AC 30 ms
10,172 KB
testcase_06 AC 31 ms
10,172 KB
testcase_07 AC 30 ms
10,172 KB
testcase_08 AC 30 ms
10,172 KB
testcase_09 AC 31 ms
10,172 KB
testcase_10 AC 30 ms
10,172 KB
testcase_11 AC 31 ms
10,176 KB
testcase_12 AC 647 ms
39,780 KB
testcase_13 AC 706 ms
44,288 KB
testcase_14 AC 689 ms
42,944 KB
testcase_15 AC 643 ms
33,596 KB
testcase_16 AC 668 ms
41,912 KB
testcase_17 AC 646 ms
33,704 KB
testcase_18 AC 633 ms
37,116 KB
testcase_19 AC 662 ms
41,968 KB
testcase_20 AC 623 ms
37,776 KB
testcase_21 AC 659 ms
41,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, m = map(int, input().split())
    S = input()
    T = input()

    dp = [[f_inf] * (m + 1) for _ in range(n + 1)]
    dp[0][0] = 0
    for i in range(n + 1):
        for j in range(m + 1):
            if i == 0 or j == 0:
                dp[i][j] = min(dp[i][j], max(i, j))
            else:
                x = 0 if S[i - 1] == T[j - 1] else 1
                dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1, dp[i][j - 1] + 1, dp[i - 1][j - 1] + x)
    print(dp[-1][-1])


if __name__ == '__main__':
    resolve()
0