結果

問題 No.225 文字列変更(medium)
ユーザー strangerxxxstrangerxxx
提出日時 2022-05-13 11:30:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 124 ms / 5,000 ms
コード長 716 bytes
コンパイル時間 758 ms
コンパイル使用メモリ 87,112 KB
実行使用メモリ 84,164 KB
最終ジャッジ日時 2023-09-28 14:09:37
合計ジャッジ時間 3,908 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
76,244 KB
testcase_01 AC 112 ms
81,820 KB
testcase_02 AC 74 ms
71,216 KB
testcase_03 AC 72 ms
71,208 KB
testcase_04 AC 71 ms
71,100 KB
testcase_05 AC 71 ms
71,292 KB
testcase_06 AC 73 ms
71,228 KB
testcase_07 AC 72 ms
71,528 KB
testcase_08 AC 71 ms
71,300 KB
testcase_09 AC 72 ms
71,092 KB
testcase_10 AC 73 ms
71,292 KB
testcase_11 AC 73 ms
71,528 KB
testcase_12 AC 122 ms
83,816 KB
testcase_13 AC 124 ms
84,164 KB
testcase_14 AC 121 ms
84,156 KB
testcase_15 AC 110 ms
84,016 KB
testcase_16 AC 122 ms
84,080 KB
testcase_17 AC 115 ms
83,676 KB
testcase_18 AC 118 ms
83,596 KB
testcase_19 AC 119 ms
83,792 KB
testcase_20 AC 119 ms
83,396 KB
testcase_21 AC 121 ms
83,808 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