結果
問題 | No.2759 Take Pictures, Elements? |
ユーザー |
![]() |
提出日時 | 2024-05-17 23:14:56 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 768 bytes |
コンパイル時間 | 286 ms |
コンパイル使用メモリ | 82,368 KB |
実行使用メモリ | 142,740 KB |
最終ジャッジ日時 | 2024-12-20 15:17:18 |
合計ジャッジ時間 | 10,197 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 TLE * 1 |
ソースコード
from collections import defaultdict as ddimport bisectN,Q = map(int, input().split())A = list(map(int, input().split()))B = list(map(int, input().split()))idx = dd(list)for i in range(N):idx[A[i]].append(i)ans = 0pre = 0dp = [ [float("inf") for i in range(N)] for _ in range(Q+1) ]dp[0][0] = 0for i in range(Q):"""r = bisect.bisect_left(idx[B[i]], pre)r = min(len(idx[B[i]])-1,r)l = max(0, r-1)if abs(idx[B[i]][r]-pre)<abs(idx[B[i]][l]-pre):ans += abs(idx[B[i]][r]-pre)pre = idx[B[i]][r]else:ans += abs(idx[B[i]][l]-pre)pre = idx[B[i]][l]"""for j in idx[B[i]]:for k in range(N):dp[i+1][j] = min(dp[i+1][j], dp[i][k]+abs(k-j))print(min(dp[-1]))