結果

問題 No.318 学学学学学
ユーザー lloyzlloyz
提出日時 2023-04-28 00:03:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 212 ms / 2,000 ms
コード長 756 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 108,032 KB
最終ジャッジ日時 2024-04-28 12:29:09
合計ジャッジ時間 6,481 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,040 KB
testcase_01 AC 74 ms
77,312 KB
testcase_02 AC 88 ms
81,536 KB
testcase_03 AC 72 ms
75,392 KB
testcase_04 AC 80 ms
80,384 KB
testcase_05 AC 147 ms
108,032 KB
testcase_06 AC 180 ms
99,712 KB
testcase_07 AC 186 ms
96,256 KB
testcase_08 AC 187 ms
94,336 KB
testcase_09 AC 186 ms
92,416 KB
testcase_10 AC 176 ms
92,032 KB
testcase_11 AC 142 ms
107,904 KB
testcase_12 AC 212 ms
99,840 KB
testcase_13 AC 199 ms
96,512 KB
testcase_14 AC 197 ms
94,336 KB
testcase_15 AC 193 ms
92,160 KB
testcase_16 AC 185 ms
91,904 KB
testcase_17 AC 164 ms
98,816 KB
testcase_18 AC 181 ms
98,816 KB
testcase_19 AC 153 ms
98,944 KB
testcase_20 AC 176 ms
90,368 KB
testcase_21 AC 43 ms
53,888 KB
testcase_22 AC 42 ms
54,016 KB
testcase_23 AC 43 ms
54,144 KB
testcase_24 AC 42 ms
54,144 KB
testcase_25 AC 42 ms
53,760 KB
testcase_26 AC 43 ms
54,016 KB
testcase_27 AC 41 ms
54,144 KB
testcase_28 AC 40 ms
54,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
from heapq import heappush, heappop

n = int(input())
A = list(map(int, input().split()))

counter = defaultdict(int)
for i in range(n):
    counter[A[i]] += 1

ANS = [-1 for _ in range(n)]
H = []
for i in range(n):
    a = A[i]
    if len(H) == 0:
        ANS[i] = a
    else:
        max_ = -H[0]
        if max_ > a:
            ANS[i] = max_
        else:
            ANS[i] = a
    counter[a] -= 1
    if counter[a] > 0:
        heappush(H, -a)
    elif counter[a] == 0 and len(H) > 0:
        if a == -H[0]:
            heappop(H)
            while H:
                max_ = -H[0]
                if counter[max_] == 0:
                    heappop(H)
                    continue
                break
print(*ANS)
0