結果

問題 No.225 文字列変更(medium)
ユーザー tookunn_1213tookunn_1213
提出日時 2017-03-29 21:15:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,850 ms / 5,000 ms
コード長 406 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 10,988 KB
実行使用メモリ 43,152 KB
最終ジャッジ日時 2023-09-20 20:18:01
合計ジャッジ時間 21,101 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 720 ms
20,304 KB
testcase_01 AC 1,221 ms
30,656 KB
testcase_02 AC 16 ms
7,916 KB
testcase_03 AC 15 ms
7,960 KB
testcase_04 AC 16 ms
7,804 KB
testcase_05 AC 15 ms
7,776 KB
testcase_06 AC 15 ms
7,856 KB
testcase_07 AC 16 ms
7,816 KB
testcase_08 AC 16 ms
7,808 KB
testcase_09 AC 16 ms
7,860 KB
testcase_10 AC 16 ms
7,920 KB
testcase_11 AC 16 ms
7,912 KB
testcase_12 AC 1,694 ms
37,932 KB
testcase_13 AC 1,850 ms
43,152 KB
testcase_14 AC 1,771 ms
41,204 KB
testcase_15 AC 1,658 ms
31,664 KB
testcase_16 AC 1,714 ms
40,504 KB
testcase_17 AC 1,671 ms
32,656 KB
testcase_18 AC 1,649 ms
35,392 KB
testcase_19 AC 1,681 ms
40,160 KB
testcase_20 AC 1,600 ms
36,116 KB
testcase_21 AC 1,690 ms
39,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
S = input()
T = input()
INF = 10**9+7
dp = [[INF for j in range(M+1)]for i 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):
		dp[i][j] = min(dp[i][j],dp[i-1][j]+1)
		dp[i][j] = min(dp[i][j],dp[i][j-1]+1)
		dp[i][j] = min(dp[i][j],dp[i-1][j-1] + (0 if S[i-1] == T[j-1] else 1))
print(dp[N][M])
0