結果
問題 | No.2248 max(C)-min(C) |
ユーザー | nephrologist |
提出日時 | 2023-03-20 10:03:49 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,162 ms / 3,000 ms |
コード長 | 1,631 bytes |
コンパイル時間 | 208 ms |
コンパイル使用メモリ | 81,844 KB |
実行使用メモリ | 227,112 KB |
最終ジャッジ日時 | 2023-10-18 18:02:09 |
合計ジャッジ時間 | 23,608 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
53,616 KB |
testcase_01 | AC | 37 ms
53,616 KB |
testcase_02 | AC | 39 ms
53,616 KB |
testcase_03 | AC | 49 ms
64,224 KB |
testcase_04 | AC | 45 ms
61,996 KB |
testcase_05 | AC | 40 ms
55,664 KB |
testcase_06 | AC | 61 ms
70,852 KB |
testcase_07 | AC | 62 ms
70,920 KB |
testcase_08 | AC | 68 ms
72,948 KB |
testcase_09 | AC | 60 ms
70,844 KB |
testcase_10 | AC | 41 ms
55,664 KB |
testcase_11 | AC | 66 ms
72,924 KB |
testcase_12 | AC | 52 ms
64,232 KB |
testcase_13 | AC | 61 ms
68,788 KB |
testcase_14 | AC | 64 ms
70,864 KB |
testcase_15 | AC | 63 ms
70,868 KB |
testcase_16 | AC | 51 ms
64,224 KB |
testcase_17 | AC | 62 ms
70,936 KB |
testcase_18 | AC | 243 ms
114,528 KB |
testcase_19 | AC | 105 ms
79,784 KB |
testcase_20 | AC | 272 ms
118,696 KB |
testcase_21 | AC | 265 ms
118,828 KB |
testcase_22 | AC | 213 ms
107,204 KB |
testcase_23 | AC | 167 ms
98,180 KB |
testcase_24 | AC | 125 ms
82,604 KB |
testcase_25 | AC | 259 ms
115,496 KB |
testcase_26 | AC | 243 ms
109,816 KB |
testcase_27 | AC | 250 ms
115,724 KB |
testcase_28 | AC | 102 ms
78,344 KB |
testcase_29 | AC | 248 ms
114,824 KB |
testcase_30 | AC | 151 ms
92,432 KB |
testcase_31 | AC | 268 ms
119,144 KB |
testcase_32 | AC | 123 ms
83,888 KB |
testcase_33 | AC | 153 ms
90,348 KB |
testcase_34 | AC | 294 ms
119,900 KB |
testcase_35 | AC | 286 ms
119,284 KB |
testcase_36 | AC | 264 ms
119,076 KB |
testcase_37 | AC | 181 ms
105,304 KB |
testcase_38 | AC | 1,001 ms
183,592 KB |
testcase_39 | AC | 979 ms
182,976 KB |
testcase_40 | AC | 1,027 ms
181,236 KB |
testcase_41 | AC | 942 ms
163,284 KB |
testcase_42 | AC | 1,020 ms
184,756 KB |
testcase_43 | AC | 946 ms
170,684 KB |
testcase_44 | AC | 1,031 ms
183,584 KB |
testcase_45 | AC | 820 ms
160,368 KB |
testcase_46 | AC | 518 ms
109,452 KB |
testcase_47 | AC | 1,025 ms
184,668 KB |
testcase_48 | AC | 953 ms
226,692 KB |
testcase_49 | AC | 1,146 ms
225,624 KB |
testcase_50 | AC | 1,124 ms
225,152 KB |
testcase_51 | AC | 1,162 ms
227,112 KB |
testcase_52 | AC | 1,112 ms
225,136 KB |
testcase_53 | AC | 268 ms
93,860 KB |
ソースコード
import sys input = sys.stdin.buffer.readline from heapq import heappop, heappush n = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) bigpq = [] smallpq = [] # initialize # a,b,half(a,b)の順に3*i, 3*i+1, 3*i+2のidxをふることにする for i in range(n): a, b = A[i], B[i] if a > b: heappush(bigpq, (-b, 3 * i + 1)) heappush(smallpq, (b, 3 * i + 1)) else: heappush(bigpq, (-a, 3 * i)) heappush(smallpq, (a, 3 * i)) cnt = [0] * n ans = 1 << 100 finished = set() while True: # print(ans) # print(smallpq) # print(bigpq) now_minimum, smallidx = heappop(smallpq) # smallidxのものはbiggestとして使えない finished.add(smallidx) # 使用済みbigpqだとアウト while bigpq: if bigpq[0][1] in finished: heappop(bigpq) else: break # 使える最大候補がない if not bigpq: break biggest, bigidx = bigpq[0] biggest *= -1 ans = min(ans, biggest - now_minimum) biggest *= -1 # smallidxと同じiのもので、次のものを追加する。 idx = smallidx // 3 cnt[idx] += 1 a, b = A[idx], B[idx] if cnt[idx] == 1: v = (a + b) // 2 heappush(bigpq, (-v, 3 * idx + 2)) heappush(smallpq, (v, 3 * idx + 2)) elif cnt[idx] == 2: if a > b: heappush(bigpq, (-a, 3 * idx)) heappush(smallpq, (a, 3 * idx)) else: heappush(bigpq, (-b, 3 * idx + 1)) heappush(smallpq, (b, 3 * idx + 1)) else: break print(ans)