結果
| 問題 | No.2759 Take Pictures, Elements? |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-05-28 11:27:05 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 936 ms / 2,000 ms |
| + 687µs | |
| コード長 | 769 bytes |
| 記録 | |
| コンパイル時間 | 221 ms |
| コンパイル使用メモリ | 96,240 KB |
| 実行使用メモリ | 84,124 KB |
| 最終ジャッジ日時 | 2026-07-12 13:49:53 |
| 合計ジャッジ時間 | 4,234 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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()))