結果

問題 No.2759 Take Pictures, Elements?
ユーザー sasa8uyauya
提出日時 2024-09-21 17:12:51
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 678 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 82,276 KB
実行使用メモリ 240,864 KB
最終ジャッジ日時 2025-06-20 13:21:55
合計ジャッジ時間 7,167 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 RE * 1
other AC * 2 RE * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
e=[[] for i in range((m+1)*n)]
for i in range(m+1):
  for j in range(n):
    if j+1<n:
      e[i*(m+1)+j]+=[(i*(m+1)+j+1,1)]
    if j-1>=0:
      e[i*(m+1)+j]+=[(i*(m+1)+j-1,1)]
for i in range(m):
  for j in range(n):
    if a[j]==b[i]:
      e[i*(m+1)+j]+=[((i+1)*(m+1)+j,0)]
from collections import deque
q=deque()
X=10**10
v=[X]*(m+1)*n
v[0]=0
q.append((v[0],0))
while len(q)>0:
  sc,sp=q.popleft()
  for tp,tc in e[sp]:
    if v[tp]>sc+tc:
      v[tp]=sc+tc
      if tc:
        q.append((v[tp],tp))
      else:
        q.appendleft((v[tp],tp))
print(min(v[(m+1)*(n-1):(m+1)*n]))
0