結果

問題 No.225 文字列変更(medium)
ユーザー XYXY
提出日時 2020-10-26 08:47:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 522 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 10,872 KB
実行使用メモリ 43,052 KB
最終ジャッジ日時 2023-09-29 02:27:36
合計ジャッジ時間 12,757 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 15 ms
7,788 KB
testcase_03 AC 16 ms
7,840 KB
testcase_04 AC 16 ms
7,776 KB
testcase_05 WA -
testcase_06 AC 16 ms
7,768 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 16 ms
7,768 KB
testcase_12 AC 949 ms
38,224 KB
testcase_13 AC 1,047 ms
43,052 KB
testcase_14 AC 1,003 ms
41,076 KB
testcase_15 AC 967 ms
31,900 KB
testcase_16 AC 1,004 ms
40,884 KB
testcase_17 AC 977 ms
32,112 KB
testcase_18 AC 957 ms
35,604 KB
testcase_19 AC 981 ms
40,040 KB
testcase_20 AC 918 ms
36,176 KB
testcase_21 AC 975 ms
39,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

nm = input().rstrip().split()
n, m = int(nm[0]), int(nm[1])
S = input().rstrip()
T = input().rstrip()
dp = [[0 for j in range(n+1)] for i in range(m+1)]
for i in range(m):
    dp[i][0] = i
for j in range(n):
    dp[0][j] = j
# dp[i][j]: Sのj文字目までをTのi文字目までに変換するための最小操作回数
for i in range(m):
    for j in range(n):
        if T[i] == S[j]:
            x = 0
        else:
            x = 1
        dp[i+1][j+1] = min(dp[i][j+1]+1, dp[i+1][j]+1, dp[i][j]+x)
print(dp[m][n])
0