結果
| 問題 |
No.1816 MUL-DIV Game
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-01-26 02:55:41 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 353 ms / 2,000 ms |
| コード長 | 1,368 bytes |
| コンパイル時間 | 184 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 101,600 KB |
| 最終ジャッジ日時 | 2024-09-28 07:26:47 |
| 合計ジャッジ時間 | 6,634 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
## https://yukicoder.me/problems/no/1816
import heapq
def main():
N = int(input())
A = list(map(int, input().split()))
A.sort()
index = [False] * (2 * N)
min_queue = []
max_queue = []
for i in range(N):
heapq.heappush(min_queue, (A[i], i))
for i in range(N):
heapq.heappush(max_queue, (-A[i], i))
for turn in range(N - 1):
if turn % 2 == 0:
array = []
while len(array) < 2:
min_value, min_index = heapq.heappop(min_queue)
if not index[min_index]:
array.append(min_value)
index[min_index] = True
x = array[0] * array[1]
heapq.heappush(min_queue, (x, N + turn))
heapq.heappush(max_queue, (-x, N + turn))
else:
array_count = 0
while array_count < 2:
_, max_index = heapq.heappop(max_queue)
if not index[max_index]:
array_count += 1
index[max_index] = True
heapq.heappush(min_queue, (1, N + turn))
heapq.heappush(max_queue, (-1, N + turn))
while len(min_queue) > 0:
min_value, min_index = heapq.heappop(min_queue)
if not index[min_index]:
print(min_value)
break
if __name__ == "__main__":
main()