結果
問題 | No.318 学学学学学 |
ユーザー |
|
提出日時 | 2023-04-28 00:03:57 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 232 ms / 2,000 ms |
コード長 | 756 bytes |
コンパイル時間 | 501 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 107,904 KB |
最終ジャッジ日時 | 2024-11-17 03:59:01 |
合計ジャッジ時間 | 6,473 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
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)