結果

問題 No.2759 Take Pictures, Elements?
ユーザー ikemizu-daiki-np
提出日時 2024-05-27 19:03:21
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 800 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 18,084 KB
最終ジャッジ日時 2025-06-20 13:21:23
合計ジャッジ時間 6,559 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other TLE * 1 -- * 20
権限があれば一括ダウンロードができます

ソースコード

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