結果

問題 No.2759 Take Pictures, Elements?
ユーザー 👑 timitimi
提出日時 2024-05-17 22:41:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 474 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 82,412 KB
実行使用メモリ 77,072 KB
最終ジャッジ日時 2024-05-17 22:41:13
合計ジャッジ時間 2,534 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
76,512 KB
testcase_01 AC 111 ms
77,072 KB
testcase_02 AC 34 ms
53,612 KB
testcase_03 AC 33 ms
52,692 KB
testcase_04 AC 33 ms
52,216 KB
testcase_05 AC 33 ms
53,104 KB
testcase_06 AC 34 ms
52,548 KB
testcase_07 AC 36 ms
53,672 KB
testcase_08 AC 33 ms
52,600 KB
testcase_09 AC 75 ms
76,296 KB
testcase_10 AC 77 ms
76,356 KB
testcase_11 AC 75 ms
76,212 KB
testcase_12 AC 74 ms
76,352 KB
testcase_13 AC 80 ms
76,448 KB
testcase_14 AC 74 ms
76,480 KB
testcase_15 AC 77 ms
76,488 KB
testcase_16 AC 78 ms
76,424 KB
testcase_17 AC 78 ms
76,316 KB
testcase_18 AC 80 ms
76,760 KB
testcase_19 AC 80 ms
76,456 KB
testcase_20 AC 82 ms
76,624 KB
testcase_21 AC 36 ms
53,708 KB
testcase_22 AC 33 ms
52,476 KB
testcase_23 AC 33 ms
52,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,Q=map(int, input().split())
A=list(map(int, input().split()))
B=list(map(int, input().split()))

D={}
for i in range(N):
  b=A[i]
  if b not in D:
    D[b]=[]
  D[b].append(i)

dp=[10**10]*N 
dp[0]=0
for b in B:
  nex=D[b]
  L=[10**10]*N;R=[10**10]*N;ndp=[10**10]*N 
  l=10**10;r=10**10
  for i in range(N):
    l=min(dp[i],l+1)
    if A[i]==b:
      ndp[i]=min(ndp[i],l)
    j=-1-i
    r=min(dp[j],r+1)
    if A[j]==b:
      ndp[j]=min(ndp[j],r) 
  dp=ndp

print(min(dp))
0