結果

問題 No.1816 MUL-DIV Game
ユーザー rlangevinrlangevin
提出日時 2023-02-19 01:09:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 537 ms / 2,000 ms
コード長 1,236 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 87,040 KB
実行使用メモリ 98,200 KB
最終ジャッジ日時 2023-09-27 12:46:53
合計ジャッジ時間 8,796 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,168 KB
testcase_01 AC 80 ms
71,428 KB
testcase_02 AC 78 ms
71,356 KB
testcase_03 AC 76 ms
70,960 KB
testcase_04 AC 77 ms
71,156 KB
testcase_05 AC 77 ms
70,948 KB
testcase_06 AC 78 ms
71,180 KB
testcase_07 AC 77 ms
71,212 KB
testcase_08 AC 78 ms
71,424 KB
testcase_09 AC 111 ms
77,388 KB
testcase_10 AC 130 ms
83,716 KB
testcase_11 AC 127 ms
82,240 KB
testcase_12 AC 123 ms
80,400 KB
testcase_13 AC 369 ms
90,216 KB
testcase_14 AC 296 ms
85,316 KB
testcase_15 AC 322 ms
86,560 KB
testcase_16 AC 226 ms
80,332 KB
testcase_17 AC 516 ms
97,060 KB
testcase_18 AC 421 ms
93,364 KB
testcase_19 AC 384 ms
87,232 KB
testcase_20 AC 445 ms
96,412 KB
testcase_21 AC 276 ms
83,668 KB
testcase_22 AC 266 ms
82,856 KB
testcase_23 AC 77 ms
71,500 KB
testcase_24 AC 77 ms
71,508 KB
testcase_25 AC 485 ms
96,504 KB
testcase_26 AC 150 ms
91,572 KB
testcase_27 AC 483 ms
96,648 KB
testcase_28 AC 148 ms
91,612 KB
testcase_29 AC 537 ms
98,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

class QuasiBinaryTree:
    def __init__(self, rule="min"):
        if rule == "max":
            self.pm = -1
        else:
            self.pm = 1
 
        self.inf = 10**18
        self.P = [self.inf]
        self.Q = []
 
    def insert(self, x):
        heappush(self.P, x * self.pm)
 
    def erase(self, x):
        heappush(self.Q, x * self.pm)
 
    def top(self):
        while self.Q and (self.P[0] == self.Q[0]):
            heappop(self.P)
            heappop(self.Q)
        return self.P[0] * self.pm


N = int(input())
A = list(map(int, input().split()))
T1 = QuasiBinaryTree("min")
T2 = QuasiBinaryTree("max")
for a in A:
    T1.insert(a)
    T2.insert(a)

if N == 1:
    print(A[0])
    exit()
elif N == 2:
    print(A[0] * A[1])
    exit()
elif N % 2:
    print(1)
    exit()
for i in range(N - 1):
    if i % 2 == 0:
        a = T1.top()
        T1.erase(a)
        b = T1.top()
        T1.erase(b)
        T1.insert(a * b)
        T2.erase(a)
        T2.erase(b)
        T2.insert(a * b)
    else:
        a = T2.top()
        T2.erase(a)
        b = T2.top()
        T2.erase(b)
        T2.insert(1)
        T1.erase(a)
        T1.erase(b)
        T1.insert(1)
                
print(T1.top())
0