結果

問題 No.2759 Take Pictures, Elements?
ユーザー tknr
提出日時 2024-05-28 12:08:41
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 861 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 82,792 KB
実行使用メモリ 848,912 KB
最終ジャッジ日時 2025-06-20 13:21:43
合計ジャッジ時間 6,252 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other MLE * 1 -- * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

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

data = []
current_index = 0

for idx, b in enumerate(B):
    if idx == 0:
        target_indexes = [i for i, j in enumerate(A) if j == b]
        res = []
        for index in target_indexes:
            cost = abs(index - current_index)
            res.append({"index": index, "cost": cost})
        data.append(res)
    else:
        current_indexes = data[idx - 1]
        target_indexes = [i for i, j in enumerate(A) if j == b]
        res = []
        for c_index in current_indexes:
            for t_index in target_indexes:
                cost = c_index["cost"] + abs(t_index - c_index["index"])
                res.append({"index": t_index, "cost": cost})
        data.append(res)

print(sorted(data[N - 2], key=lambda x: x["cost"])[0]["cost"])
0