結果

問題 No.2453 Seat Allocation
ユーザー fiblonariafiblonaria
提出日時 2023-09-05 14:51:31
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,455 bytes
コンパイル時間 420 ms
コンパイル使用メモリ 87,280 KB
実行使用メモリ 109,356 KB
最終ジャッジ日時 2023-09-05 14:51:49
合計ジャッジ時間 16,840 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,180 KB
testcase_01 AC 76 ms
71,512 KB
testcase_02 AC 76 ms
71,448 KB
testcase_03 RE -
testcase_04 AC 78 ms
71,416 KB
testcase_05 AC 989 ms
108,688 KB
testcase_06 AC 273 ms
91,960 KB
testcase_07 RE -
testcase_08 AC 266 ms
80,592 KB
testcase_09 AC 1,200 ms
109,356 KB
testcase_10 AC 1,319 ms
108,648 KB
testcase_11 AC 1,343 ms
108,972 KB
testcase_12 AC 302 ms
91,728 KB
testcase_13 AC 412 ms
91,960 KB
testcase_14 AC 191 ms
91,472 KB
testcase_15 AC 521 ms
92,228 KB
testcase_16 AC 393 ms
91,404 KB
testcase_17 AC 77 ms
71,192 KB
testcase_18 AC 911 ms
94,480 KB
testcase_19 AC 1,040 ms
104,128 KB
testcase_20 AC 489 ms
86,992 KB
testcase_21 AC 575 ms
87,876 KB
testcase_22 AC 797 ms
92,388 KB
testcase_23 RE -
testcase_24 AC 79 ms
71,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class heap:
    #comp:比較関数 小さいものから順に取り出す
    def __init__(s, comp = lambda x:x):
        s.comp = comp
        s.values = []
    #index と 子供たちの位置関係を調整
    def adjust(s, index):
        next = None
        cur = s.comp(s.values[index])
        for i in range(index * 2 + 1, min(index * 2 + 3, len(s.values))):
            if cur > s.comp(s.values[i]):
                next = i
                cur = s.comp(s.values[i])
        if next != None:
            s.values[index], s.values[next] = s.values[next], s.values[index]
            return next
        else:
            return None
    def push(s, value):
        s.values.append(value)
        index = (len(s.values) - 2) // 2
        while index >= 0:
            s.adjust(index)
            index = (index - 1) // 2
    def pop(s):
        if len(s.values) == 0:
            return None
        if len(s.values) == 1:
            return s.values.pop()
        ret = s.values[0]
        s.values[0] = s.values.pop()
        index = 0
        while index != None:
            index = s.adjust(index)
        return ret
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
number = [0 for i in range(N)]
H = heap()
for i in range(N):
	H.push((-(A[i] / B[0]), i))
for i in range(M):
	cur = H.pop()
	number[cur[1]] += 1
	print(cur[1] + 1)
	H.push((-(A[cur[1]] / B[number[cur[1]]]), cur[1]))
0