結果

問題 No.1816 MUL-DIV Game
ユーザー LyricalMaestroLyricalMaestro
提出日時 2024-01-26 02:55:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 380 ms / 2,000 ms
コード長 1,368 bytes
コンパイル時間 495 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 101,096 KB
最終ジャッジ日時 2024-01-26 02:55:49
合計ジャッジ時間 7,915 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 39 ms
53,460 KB
testcase_02 AC 38 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 39 ms
53,460 KB
testcase_06 AC 39 ms
53,460 KB
testcase_07 AC 38 ms
53,460 KB
testcase_08 AC 38 ms
53,460 KB
testcase_09 AC 155 ms
77,576 KB
testcase_10 AC 241 ms
84,876 KB
testcase_11 AC 216 ms
83,964 KB
testcase_12 AC 201 ms
81,892 KB
testcase_13 AC 255 ms
89,916 KB
testcase_14 AC 188 ms
82,620 KB
testcase_15 AC 205 ms
84,868 KB
testcase_16 AC 136 ms
77,600 KB
testcase_17 AC 299 ms
97,148 KB
testcase_18 AC 284 ms
95,144 KB
testcase_19 AC 194 ms
83,964 KB
testcase_20 AC 298 ms
97,460 KB
testcase_21 AC 178 ms
81,752 KB
testcase_22 AC 165 ms
79,836 KB
testcase_23 AC 38 ms
53,460 KB
testcase_24 AC 39 ms
53,460 KB
testcase_25 AC 337 ms
101,096 KB
testcase_26 AC 380 ms
100,968 KB
testcase_27 AC 331 ms
100,968 KB
testcase_28 AC 371 ms
100,968 KB
testcase_29 AC 334 ms
100,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

## 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()
0