結果

問題 No.2453 Seat Allocation
ユーザー rlangevinrlangevin
提出日時 2023-09-01 22:55:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,123 bytes
コンパイル時間 474 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 115,832 KB
最終ジャッジ日時 2023-09-01 22:56:05
合計ジャッジ時間 8,678 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,520 KB
testcase_01 AC 72 ms
71,400 KB
testcase_02 AC 72 ms
71,432 KB
testcase_03 AC 72 ms
71,200 KB
testcase_04 WA -
testcase_05 AC 390 ms
115,832 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 171 ms
93,224 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import *
class RationalHeap:
    def __init__(self):
        self.H = []
        
    def add(self, A, B, n, ind):
        g = gcd(A, B)
        A //= g
        B //= g
        self.H.append((A, B, n, ind))
        now = len(self.H) - 1
        while now:
            par = (now - 1) // 2
            # print("add", now, par, self.H)
            if self.check(now, par):
                self.H[now], self.H[par] = self.H[par], self.H[now]
                par = now
            else:
                break
        return 
                
    def pop(self):
        ra, rb, rn, ri = self.H[0]
        a, b, n, i = self.H.pop()
        self.H[0] = (a, b, n, i)
        now = 0
        while True:
            
            if len(self.H) < 2 * now + 2:
                break
            ch1 = 2 * now + 1
            if len(self.H) < 2 * now + 3:
                if self.check(ch1, now):
                    self.H[now], self.H[ch1] = self.H[ch1], self.H[now]
                    now = ch1
                else:
                    break
            else:
                ch2 = 2 * now + 2
                if self.check(ch1, ch2):
                    ch = ch1
                else:
                    ch = ch2
                if self.check(ch, now):
                    self.H[now], self.H[ch] = self.H[ch], self.H[now]
                    now = ch
                else:
                    break

        return rn, ri
    
                
    def check(self, p, q):
        # print("test", p, q)
        a1, b1, n1, i1 = self.H[p]
        a2, b2, n2, i2 = self.H[q]
        if a1 == a2 and b1 == b2:
            if n1 < n2:
                return True
            else:
                return False
        else:
            if a1 * b2 > b1 * a2:
                return True
            else:
                return False

    
    
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split())) + [10 ** 18]
H = RationalHeap()
for i in range(N):
    H.add(A[i], B[0], i, 0)
    
for _ in range(M):
    n, i = H.pop()
    print(n + 1)
    H.add(A[n], B[i + 1], n, i + 1)
0