結果
問題 | No.2453 Seat Allocation |
ユーザー |
![]() |
提出日時 | 2023-09-01 22:28:52 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 705 ms / 2,000 ms |
コード長 | 1,316 bytes |
コンパイル時間 | 240 ms |
コンパイル使用メモリ | 82,236 KB |
実行使用メモリ | 178,908 KB |
最終ジャッジ日時 | 2025-06-20 01:45:28 |
合計ジャッジ時間 | 9,860 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
from collections import defaultdict import heapq num_to_index=defaultdict(list) N,M=map(int,input().split()) A=list(map(int,input().split())) for i in range(N): num_to_index[A[i]].append(i) c=0 sortedindex_to_index=[] index_to_sortedindex=[0]*N A.sort(reverse=True) pre=-1 for i in range(N): if(pre!=A[i]): c=0 sortedindex_to_index.append(num_to_index[A[i]][c]) index_to_sortedindex[num_to_index[A[i]][c]]=i c+=1 pre=A[i] # print(A) # print(sortedindex_to_index) # print(index_to_sortedindex) seen=defaultdict(bool) B=list(map(int,input().split())) k=-10**100 for i in range(N): A[i]*=k ans=[] def score(a,b): return A[a]//B[b]*10**12-(N-sortedindex_to_index[a])*10**6-b pre_ans=[score(0,0)] seen["0"+"_"+"0"]=True heapq.heapify(ans) while len(ans)<M: # print(pre_ans) # print(seen) m=-heapq.heappop(pre_ans) # print(m) a=index_to_sortedindex[N-(m%10**12)//10**6] b=m%10**6 # print(a,b) ans.append(sortedindex_to_index[a]) if(a+1<N and b<M and not seen[str(a+1)+"_"+str(b)]): heapq.heappush(pre_ans,score(a+1,b)) seen[str(a+1)+"_"+str(b)]=True if(a<N and b+1<M and not seen[str(a)+"_"+str(b+1)]): heapq.heappush(pre_ans,score(a,b+1)) seen[str(a)+"_"+str(b+1)]=True for i in range(M): print(ans[i]+1)