結果

問題 No.2759 Take Pictures, Elements?
ユーザー ikemizu-daiki-np
提出日時 2024-05-28 11:14:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,965 ms / 2,000 ms
コード長 800 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 82,284 KB
実行使用メモリ 76,760 KB
最終ジャッジ日時 2025-06-20 13:21:37
合計ジャッジ時間 4,712 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

x,y = map(int,input().split())	


a_list=list(map(int,input().split()))

# {val: [idx,list]}
a_dict={}


for idx, a in enumerate(a_list):
    if a in a_dict:
        a_dict[a]=[*a_dict[a], idx]
    else:
        a_dict[a]=[idx]

b_list = list(map(int,input().split()))

pre_pos=0

# {pos: total_count}
count_dict={0:0}

for b in b_list:
    pos_list=a_dict[b]
    
    temp_count_dict={}
    
    for p in pos_list:
        for key in count_dict:
            now_total=count_dict[key]
            if p in temp_count_dict:
                val=now_total+abs(p-key)
                if val < temp_count_dict[p]:
                    temp_count_dict[p]=val
            else:
                temp_count_dict[p]=now_total+abs(p-key)
    count_dict=temp_count_dict
            
print(min(count_dict.values()))
0