結果

問題 No.225 文字列変更(medium)
ユーザー yaoshimaxyaoshimax
提出日時 2015-06-13 13:36:29
言語 Python2
(2.7.18)
結果
AC  
実行時間 1,354 ms / 5,000 ms
コード長 529 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 7,192 KB
実行使用メモリ 31,956 KB
最終ジャッジ日時 2023-08-25 22:50:51
合計ジャッジ時間 16,005 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 523 ms
15,412 KB
testcase_01 AC 902 ms
23,784 KB
testcase_02 AC 11 ms
6,000 KB
testcase_03 AC 11 ms
5,996 KB
testcase_04 AC 12 ms
5,876 KB
testcase_05 AC 11 ms
6,124 KB
testcase_06 AC 11 ms
6,092 KB
testcase_07 AC 11 ms
5,952 KB
testcase_08 AC 11 ms
5,944 KB
testcase_09 AC 11 ms
5,872 KB
testcase_10 AC 12 ms
5,868 KB
testcase_11 AC 11 ms
5,860 KB
testcase_12 AC 1,238 ms
26,852 KB
testcase_13 AC 1,354 ms
31,956 KB
testcase_14 AC 1,314 ms
30,636 KB
testcase_15 AC 1,244 ms
19,336 KB
testcase_16 AC 1,276 ms
30,432 KB
testcase_17 AC 1,245 ms
19,244 KB
testcase_18 AC 1,209 ms
23,152 KB
testcase_19 AC 1,260 ms
30,488 KB
testcase_20 AC 1,189 ms
24,900 KB
testcase_21 AC 1,256 ms
29,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m=map(int,raw_input().split())
S=raw_input()
T=raw_input()
dp=[[10000 for i in range(m+1)] for j in range(n+1)]
dp[0][0]=0
for i in range(1,n+1):
    dp[i][0] = i
for j in range(1,m+1):
    dp[0][j]= j

for i in range(1, n+1):
    for j in range(1, m+1):
        if S[i-1]==T[j-1]:
            dp[i][j] = min(dp[i][j],dp[i-1][j-1])
        else:
            dp[i][j] = min(dp[i][j],1+dp[i-1][j-1])
        dp[i][j]=min(dp[i][j],dp[i-1][j]+1) # delete S[i]
        dp[i][j]=min(dp[i][j],dp[i][j-1]+1) # add T[j]
print dp[n][m]

0