結果

問題 No.2759 Take Pictures, Elements?
ユーザー rin204rin204
提出日時 2024-05-18 00:45:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 500 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 82,492 KB
実行使用メモリ 76,252 KB
最終ジャッジ日時 2024-05-18 00:45:57
合計ジャッジ時間 3,022 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
76,216 KB
testcase_01 AC 82 ms
76,252 KB
testcase_02 AC 34 ms
52,276 KB
testcase_03 AC 36 ms
53,404 KB
testcase_04 AC 34 ms
53,292 KB
testcase_05 AC 34 ms
52,668 KB
testcase_06 AC 34 ms
52,952 KB
testcase_07 AC 34 ms
52,888 KB
testcase_08 AC 35 ms
53,960 KB
testcase_09 AC 68 ms
73,680 KB
testcase_10 AC 75 ms
73,736 KB
testcase_11 AC 68 ms
73,688 KB
testcase_12 AC 69 ms
73,968 KB
testcase_13 AC 67 ms
74,764 KB
testcase_14 AC 63 ms
74,120 KB
testcase_15 AC 72 ms
74,272 KB
testcase_16 AC 72 ms
74,796 KB
testcase_17 AC 77 ms
74,268 KB
testcase_18 AC 69 ms
74,496 KB
testcase_19 AC 73 ms
74,204 KB
testcase_20 AC 70 ms
74,112 KB
testcase_21 AC 35 ms
52,624 KB
testcase_22 AC 34 ms
52,132 KB
testcase_23 AC 34 ms
53,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, Q = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
inf = 1 << 60
dp = [inf] * n
dp[0] = 0

for b in B:
    ndp = [inf] * n
    mi = inf
    for i in range(n):
        a = A[i]
        mi = min(mi + 1, dp[i])
        if a == b:
            ndp[i] = min(ndp[i], mi)
    mi = inf
    for i in range(n - 1, -1, -1):
        a = A[i]
        mi = min(mi + 1, dp[i])
        if a == b:
            ndp[i] = min(ndp[i], mi)
    dp = ndp

print(min(dp))
0