結果

問題 No.225 文字列変更(medium)
ユーザー strangerxxxstrangerxxx
提出日時 2022-05-13 11:29:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 406 ms / 5,000 ms
コード長 716 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 39,948 KB
最終ジャッジ日時 2023-09-28 14:09:33
合計ジャッジ時間 5,469 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 167 ms
19,644 KB
testcase_01 AC 284 ms
29,776 KB
testcase_02 AC 16 ms
7,920 KB
testcase_03 AC 15 ms
7,812 KB
testcase_04 AC 16 ms
7,924 KB
testcase_05 AC 15 ms
7,856 KB
testcase_06 AC 16 ms
7,756 KB
testcase_07 AC 16 ms
7,808 KB
testcase_08 AC 16 ms
7,808 KB
testcase_09 AC 16 ms
7,872 KB
testcase_10 AC 16 ms
7,904 KB
testcase_11 AC 16 ms
7,852 KB
testcase_12 AC 346 ms
33,380 KB
testcase_13 AC 406 ms
39,948 KB
testcase_14 AC 394 ms
38,200 KB
testcase_15 AC 264 ms
23,380 KB
testcase_16 AC 383 ms
37,224 KB
testcase_17 AC 265 ms
23,424 KB
testcase_18 AC 306 ms
28,412 KB
testcase_19 AC 381 ms
37,724 KB
testcase_20 AC 322 ms
30,608 KB
testcase_21 AC 373 ms
36,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def resolve():
    import sys
    input = sys.stdin.readline
    n, m = map(int, input().split())
    a = [ord(x) - ord("a") for x in input()]
    b = [ord(x) - ord("a") for x in input()]
    INF = float('inf')
    dp = [[INF] * (m + 1) for _ in range(n + 1)]
    for i in range(n):
        dp[i][0] = i
    for i in range(1, m):
        dp[0][i] = i
    for i in range(n):
        for j in range(m):
            if a[i] == b[j]:
                dp[i + 1][j + 1] = dp[i][j]
            else:
                dp[i + 1][j + 1] = min(dp[i][j],
                                       dp[i][j + 1],
                                       dp[i + 1][j]) + 1
    print(dp[-1][-1])


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