結果

問題 No.225 文字列変更(medium)
ユーザー titiatitia
提出日時 2022-07-17 04:30:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 722 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 11,092 KB
実行使用メモリ 40,868 KB
最終ジャッジ日時 2023-09-11 15:23:44
合計ジャッジ時間 22,290 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 748 ms
19,784 KB
testcase_01 AC 1,336 ms
29,956 KB
testcase_02 AC 16 ms
8,268 KB
testcase_03 AC 16 ms
8,288 KB
testcase_04 AC 16 ms
8,200 KB
testcase_05 WA -
testcase_06 AC 16 ms
8,136 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 17 ms
8,316 KB
testcase_10 AC 17 ms
8,296 KB
testcase_11 AC 17 ms
7,988 KB
testcase_12 AC 1,739 ms
36,072 KB
testcase_13 WA -
testcase_14 AC 1,826 ms
39,512 KB
testcase_15 AC 1,784 ms
30,992 KB
testcase_16 AC 1,816 ms
38,256 KB
testcase_17 AC 1,745 ms
31,128 KB
testcase_18 AC 1,705 ms
33,448 KB
testcase_19 AC 1,792 ms
38,728 KB
testcase_20 WA -
testcase_21 AC 1,750 ms
37,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

DP=[[1<<30]*m for i in range(n)]

if S[0]==T[0]:
    DP[0][0]=0
else:
    DP[0][0]=1

for i in range(n):
    for j in range(m):
        if S[i]==T[j]:
            if i-1>=0 and j-1>=0:
                DP[i][j]=min(DP[i-1][j-1],DP[i][j])
            if i-1>=0:
                DP[i][j]=min(DP[i-1][j]+1,DP[i][j])
            if j-1>=0:
                DP[i][j]=min(DP[i][j-1]+1,DP[i][j])
        else:
            if i-1>=0 and j-1>=0:
                DP[i][j]=min(DP[i-1][j-1]+1,DP[i][j])
            if i-1>=0:
                DP[i][j]=min(DP[i-1][j]+1,DP[i][j])
            if j-1>=0:
                DP[i][j]=min(DP[i][j-1]+1,DP[i][j])
            

print(DP[n-1][m-1])
0