結果
問題 |
No.2759 Take Pictures, Elements?
|
ユーザー |
|
提出日時 | 2024-05-28 11:27:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,514 ms / 2,000 ms |
コード長 | 769 bytes |
コンパイル時間 | 248 ms |
コンパイル使用メモリ | 82,092 KB |
実行使用メモリ | 76,476 KB |
最終ジャッジ日時 | 2025-06-20 13:21:38 |
合計ジャッジ時間 | 3,961 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
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, value in count_dict.items(): if p in temp_count_dict: val=value+abs(p-key) if val < temp_count_dict[p]: temp_count_dict[p]=val else: temp_count_dict[p]=value+abs(p-key) count_dict=temp_count_dict print(min(count_dict.values()))