結果

問題 No.225 文字列変更(medium)
ユーザー titiatitia
提出日時 2022-07-17 04:19:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 722 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 10,936 KB
実行使用メモリ 37,592 KB
最終ジャッジ日時 2023-09-11 15:12:58
合計ジャッジ時間 19,711 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 706 ms
19,228 KB
testcase_01 AC 1,257 ms
29,260 KB
testcase_02 AC 16 ms
7,848 KB
testcase_03 AC 16 ms
7,860 KB
testcase_04 AC 16 ms
7,816 KB
testcase_05 WA -
testcase_06 AC 16 ms
7,808 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 16 ms
7,784 KB
testcase_11 AC 16 ms
7,908 KB
testcase_12 AC 1,577 ms
28,988 KB
testcase_13 WA -
testcase_14 AC 1,745 ms
35,580 KB
testcase_15 AC 1,264 ms
17,312 KB
testcase_16 AC 1,734 ms
35,288 KB
testcase_17 AC 1,291 ms
17,104 KB
testcase_18 AC 1,388 ms
23,000 KB
testcase_19 AC 1,700 ms
35,980 KB
testcase_20 WA -
testcase_21 AC 1,666 ms
33,768 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],DP[i][j])
            #if j-1>=0:
            #    DP[i][j]=min(DP[i][j-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