結果
| 問題 | No.1816 MUL-DIV Game | 
| コンテスト | |
| ユーザー |  gew1fw | 
| 提出日時 | 2025-06-12 19:49:02 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                RE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 918 bytes | 
| コンパイル時間 | 248 ms | 
| コンパイル使用メモリ | 81,924 KB | 
| 実行使用メモリ | 79,280 KB | 
| 最終ジャッジ日時 | 2025-06-12 19:49:07 | 
| 合計ジャッジ時間 | 5,518 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 6 RE * 1 TLE * 1 -- * 19 | 
ソースコード
import heapq
def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    N = int(data[0])
    A = list(map(int, data[1:N+1]))
    
    if N == 1:
        print(A[0])
        return
    if N == 2:
        print(A[0] * A[1])
        return
    if 1 in A:
        product = 1
        for num in A:
            product *= num
        print(product)
        return
    
    B = (N - 1) // 2
    min_heap = A.copy()
    max_heap = [-x for x in A]
    heapq.heapify(min_heap)
    heapq.heapify(max_heap)
    
    product = 1
    for num in A:
        product *= num
    
    for _ in range(B):
        a = heapq.heappop(min_heap)
        b = -heapq.heappop(max_heap)
        
        c = (b + a - 1) // a
        
        product = product // (a * b) * c
        
        heapq.heappush(min_heap, c)
        heapq.heappush(max_heap, -c)
    
    print(product)
if __name__ == "__main__":
    main()
            
            
            
        