結果

問題 No.2759 Take Pictures, Elements?
ユーザー 👑 rin204
提出日時 2024-05-18 00:45:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 500 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 82,604 KB
実行使用メモリ 76,428 KB
最終ジャッジ日時 2025-06-20 13:19:31
合計ジャッジ時間 2,665 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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