結果

問題 No.225 文字列変更(medium)
ユーザー しらっ亭しらっ亭
提出日時 2015-06-17 22:00:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,373 ms / 5,000 ms
コード長 503 bytes
コンパイル時間 286 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 157,636 KB
最終ジャッジ日時 2023-08-25 23:03:00
合計ジャッジ時間 15,940 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 520 ms
76,932 KB
testcase_01 AC 889 ms
97,668 KB
testcase_02 AC 16 ms
7,804 KB
testcase_03 AC 16 ms
7,816 KB
testcase_04 AC 16 ms
7,812 KB
testcase_05 AC 16 ms
7,824 KB
testcase_06 AC 16 ms
7,828 KB
testcase_07 AC 16 ms
7,856 KB
testcase_08 AC 15 ms
7,864 KB
testcase_09 AC 16 ms
7,816 KB
testcase_10 AC 16 ms
7,824 KB
testcase_11 AC 17 ms
7,824 KB
testcase_12 AC 1,259 ms
147,296 KB
testcase_13 AC 1,373 ms
157,636 KB
testcase_14 AC 1,330 ms
154,284 KB
testcase_15 AC 1,248 ms
141,500 KB
testcase_16 AC 1,275 ms
150,496 KB
testcase_17 AC 1,267 ms
142,212 KB
testcase_18 AC 1,231 ms
144,320 KB
testcase_19 AC 1,284 ms
150,360 KB
testcase_20 AC 1,200 ms
145,308 KB
testcase_21 AC 1,263 ms
149,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(s1, s2):
    d = {}

    for i in range(len(s1) + 1):
        d[i, 0] = i
    for j in range(len(s2) + 1):
        d[0, j] = j

    for i in range(1, len(s1) + 1):
        for j in range(1, len(s2) + 1):
            n = 0 if s1[i - 1] == s2[j - 1] else 1
            d[i, j] = min(d[i - 1, j] + 1, d[i, j - 1] + 1, d[i - 1, j - 1] + n)

    return d[len(s1), len(s2)]


def main():
    input()
    s1 = input()
    s2 = input()
    print(solve(s1, s2))


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