반응형 우선순위큐2 [백준 / Python] 14698번 전생했더니 슬라임 연구자였던 건에 대하여 (Hard) 문제https://www.acmicpc.net/problem/14698소스코드import heapqimport sysinput = sys.stdin.readlineT= int(input())for i in range(T): N = int(input()) ls = list(map(int, input().split())) heapq.heapify(ls) answer = 1 while len(ls) > 1: a = heapq.heappop(ls) b = heapq.heappop(ls) c = a * b answer *= c heapq.heappush(ls, c) print(answer % 1000000007) 우선순.. 2024. 9. 23. [백준 / Python] 11000번 강의실 배정 문제https://www.acmicpc.net/problem/11000 코드import heapq# 3# 1 3# 2 4# 3 5heap = []# heapq.heappush(heap, 50)# heapq.heappush(heap, 10)# heapq.heappush(heap, 20)n = int(input())datalist = []size = 0for i in range(n): datalist.append(tuple(map(int, input().split())))datalist.sort(key=lambda x : (x[0]))# print(datalist)# data (int, int)for data in datalist: if len(heap) > 0: if heap[0].. 2024. 5. 29. 이전 1 다음 728x90 반응형