結果

問題 No.2759 Take Pictures, Elements?
ユーザー yansi819
提出日時 2024-05-28 10:03:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 566 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 82,844 KB
実行使用メモリ 75,688 KB
最終ジャッジ日時 2025-06-20 13:21:25
合計ジャッジ時間 1,961 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

N, Q = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
now = 1
ans = 0
for b in B:
    index1, index2 = -1, -1
    if b in A[now - 1:]:
        index1 = A[now - 1:].index(b)
    if b in A[0:now]:
        index2 = A[::-1][len(A) - now:].index(b)
    d = 0
    if index1 < 0: 
        d = index2
        now -= d
    elif index2 < 0: 
        d = index1
        now += d
    else: 
        d = min(index1, index2)
        if d == index1:
            now += d
        else:
            now -= d
    ans += d
print(ans)
0