結果

問題 No.2453 Seat Allocation
ユーザー KoiKoi
提出日時 2023-09-01 22:28:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 797 ms / 2,000 ms
コード長 1,316 bytes
コンパイル時間 591 ms
コンパイル使用メモリ 87,156 KB
実行使用メモリ 184,480 KB
最終ジャッジ日時 2023-09-07 15:36:18
合計ジャッジ時間 11,763 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
71,776 KB
testcase_01 AC 92 ms
71,596 KB
testcase_02 AC 90 ms
71,752 KB
testcase_03 AC 87 ms
71,592 KB
testcase_04 AC 89 ms
71,728 KB
testcase_05 AC 645 ms
173,636 KB
testcase_06 AC 357 ms
104,652 KB
testcase_07 AC 261 ms
113,892 KB
testcase_08 AC 234 ms
84,440 KB
testcase_09 AC 797 ms
163,884 KB
testcase_10 AC 763 ms
184,480 KB
testcase_11 AC 785 ms
182,848 KB
testcase_12 AC 491 ms
120,448 KB
testcase_13 AC 429 ms
111,604 KB
testcase_14 AC 526 ms
127,888 KB
testcase_15 AC 512 ms
110,716 KB
testcase_16 AC 527 ms
115,356 KB
testcase_17 AC 91 ms
71,784 KB
testcase_18 AC 654 ms
138,528 KB
testcase_19 AC 687 ms
152,460 KB
testcase_20 AC 394 ms
104,816 KB
testcase_21 AC 459 ms
109,652 KB
testcase_22 AC 632 ms
128,896 KB
testcase_23 AC 89 ms
71,744 KB
testcase_24 AC 89 ms
71,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0