結果

問題 No.225 文字列変更(medium)
ユーザー H3PO4H3PO4
提出日時 2023-06-17 20:31:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 458 ms / 5,000 ms
コード長 448 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 10,896 KB
実行使用メモリ 37,996 KB
最終ジャッジ日時 2023-09-07 16:28:07
合計ジャッジ時間 9,091 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 257 ms
32,928 KB
testcase_01 AC 352 ms
35,300 KB
testcase_02 AC 129 ms
29,876 KB
testcase_03 AC 130 ms
29,860 KB
testcase_04 AC 134 ms
29,844 KB
testcase_05 AC 128 ms
29,768 KB
testcase_06 AC 128 ms
29,784 KB
testcase_07 AC 130 ms
29,812 KB
testcase_08 AC 129 ms
29,764 KB
testcase_09 AC 131 ms
29,800 KB
testcase_10 AC 133 ms
29,860 KB
testcase_11 AC 131 ms
29,808 KB
testcase_12 AC 433 ms
37,396 KB
testcase_13 AC 458 ms
37,924 KB
testcase_14 AC 455 ms
37,996 KB
testcase_15 AC 437 ms
37,504 KB
testcase_16 AC 442 ms
37,640 KB
testcase_17 AC 445 ms
37,456 KB
testcase_18 AC 427 ms
37,420 KB
testcase_19 AC 442 ms
37,596 KB
testcase_20 AC 423 ms
37,300 KB
testcase_21 AC 442 ms
37,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

N, M = map(int, input().split())
S = np.array(list(input()))
T = np.array(list(input()))

min1 = np.frompyfunc(lambda x, y: min(x, y) + 1, 2, 1)

eq = (S[:, None] == T[None, :])
dp = np.zeros((N + 1, M + 1), dtype=int)
dp[0] = np.arange(M + 1)
dp[:, 0] = np.arange(N + 1)
for i in range(N):
    dp[i + 1, 1:] = np.minimum(dp[i, 1:], dp[i, :-1] - eq[i])
    dp[i + 1] = min1.accumulate(dp[i + 1], dtype=np.int64)
print(dp[N, M])
0