結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 288 ms
21,920 KB
testcase_01 AC 479 ms
32,340 KB
testcase_02 AC 31 ms
10,176 KB
testcase_03 AC 31 ms
10,172 KB
testcase_04 AC 30 ms
10,172 KB
testcase_05 WA -
testcase_06 AC 30 ms
10,172 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 30 ms
10,172 KB
testcase_10 AC 30 ms
10,172 KB
testcase_11 AC 30 ms
10,176 KB
testcase_12 AC 647 ms
39,752 KB
testcase_13 WA -
testcase_14 AC 688 ms
42,904 KB
testcase_15 AC 640 ms
33,552 KB
testcase_16 AC 666 ms
41,912 KB
testcase_17 AC 645 ms
33,700 KB
testcase_18 AC 635 ms
37,084 KB
testcase_19 AC 662 ms
41,928 KB
testcase_20 WA -
testcase_21 AC 662 ms
41,268 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] + x, dp[i - 1][j] + 1, dp[i][j - 1] + 1)
    print(dp[-1][-1])


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