-
백준 1927 최소 힙파이썬 알고리즘 2022. 1. 26. 19:17
힙
- 최소 힙이 기본, import heapq
- heappush heappop
import heapq, sys N = int(sys.stdin.readline()) heap = [] for _ in range(N): x = int(sys.stdin.readline()) if x == 0: if len(heap) == 0: print(0) else: print(heapq.heappop(heap)) else: heapq.heappush(heap,x)input()썼는데 시간초과 나면 해당부분만 sys.stdin.readline()로 대체
기본함수
import heapq heap=[] heapq.heappush(heap,n) heapq.heappop(heap)'파이썬 알고리즘' 카테고리의 다른 글
백준 2164 카드2 deque (0) 2022.01.26 백준 2592 대표값 (0) 2022.01.25 백준 2490 윷놀이 (0) 2022.01.25 백준 2588 (0) 2022.01.25 백준 2309 (0) 2022.01.25