結果
| 問題 |
No.1816 MUL-DIV Game
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 14:43:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 918 bytes |
| コンパイル時間 | 286 ms |
| コンパイル使用メモリ | 82,556 KB |
| 実行使用メモリ | 267,732 KB |
| 最終ジャッジ日時 | 2025-06-12 14:43:35 |
| 合計ジャッジ時間 | 5,478 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()
gew1fw