結果

問題 No.225 文字列変更(medium)
ユーザー e-mone-mon
提出日時 2015-06-17 15:23:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,216 ms / 5,000 ms
コード長 457 bytes
コンパイル時間 428 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 43,104 KB
最終ジャッジ日時 2023-08-25 23:01:00
合計ジャッジ時間 14,313 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 437 ms
20,208 KB
testcase_01 AC 773 ms
30,824 KB
testcase_02 AC 15 ms
7,968 KB
testcase_03 AC 15 ms
7,944 KB
testcase_04 AC 16 ms
7,872 KB
testcase_05 AC 15 ms
7,928 KB
testcase_06 AC 15 ms
7,912 KB
testcase_07 AC 16 ms
7,968 KB
testcase_08 AC 15 ms
7,972 KB
testcase_09 AC 16 ms
7,940 KB
testcase_10 AC 17 ms
7,784 KB
testcase_11 AC 16 ms
7,784 KB
testcase_12 AC 1,080 ms
37,916 KB
testcase_13 AC 1,216 ms
43,104 KB
testcase_14 AC 1,154 ms
41,128 KB
testcase_15 AC 1,049 ms
31,640 KB
testcase_16 AC 1,119 ms
40,464 KB
testcase_17 AC 1,058 ms
32,764 KB
testcase_18 AC 1,074 ms
35,324 KB
testcase_19 AC 1,071 ms
40,160 KB
testcase_20 AC 1,059 ms
36,064 KB
testcase_21 AC 1,115 ms
39,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

dp = [[0 for i in range(m + 1)] for j in range(n + 1)]
for i in range(n+1):
    dp[i][0] = i
for i in range(m+1):
    dp[0][i] = i

for i in range(1,n+1):
    for j in range(1,m+1):
        ins = dp[i-1][j] + 1
        Del = dp[i][j-1] + 1
        rev = dp[i-1][j-1] + (1  if S[i-1] != T[j-1] else 0)
        dp[i][j] = min(ins,Del,rev)

print(dp[n][m])
0