結果
問題 | No.2453 Seat Allocation |
ユーザー | rlangevin |
提出日時 | 2023-09-01 23:06:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 596 ms / 2,000 ms |
コード長 | 2,123 bytes |
コンパイル時間 | 644 ms |
コンパイル使用メモリ | 86,900 KB |
実行使用メモリ | 115,820 KB |
最終ジャッジ日時 | 2023-09-07 15:37:35 |
合計ジャッジ時間 | 9,068 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 71 ms
71,440 KB |
testcase_01 | AC | 71 ms
71,716 KB |
testcase_02 | AC | 71 ms
71,712 KB |
testcase_03 | AC | 70 ms
71,748 KB |
testcase_04 | AC | 74 ms
71,728 KB |
testcase_05 | AC | 385 ms
115,820 KB |
testcase_06 | AC | 199 ms
93,824 KB |
testcase_07 | AC | 175 ms
96,676 KB |
testcase_08 | AC | 166 ms
80,672 KB |
testcase_09 | AC | 562 ms
109,960 KB |
testcase_10 | AC | 596 ms
111,584 KB |
testcase_11 | AC | 595 ms
112,536 KB |
testcase_12 | AC | 463 ms
93,276 KB |
testcase_13 | AC | 366 ms
93,576 KB |
testcase_14 | AC | 167 ms
93,804 KB |
testcase_15 | AC | 375 ms
93,252 KB |
testcase_16 | AC | 426 ms
92,452 KB |
testcase_17 | AC | 72 ms
71,320 KB |
testcase_18 | AC | 412 ms
95,624 KB |
testcase_19 | AC | 514 ms
105,692 KB |
testcase_20 | AC | 258 ms
87,780 KB |
testcase_21 | AC | 279 ms
87,904 KB |
testcase_22 | AC | 377 ms
94,024 KB |
testcase_23 | AC | 72 ms
71,808 KB |
testcase_24 | AC | 72 ms
71,420 KB |
ソースコード
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] now = par 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)