Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions INSEA-99/week06/11279_최대_힙.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# pypy3
# 시간(ms) : 164
# 공간(KB) : 10604

import sys
import heapq
input = sys.stdin.readline

pq = []
for _ in range(int(input().strip())) :
x = int(input().strip())
if x : heapq.heappush(pq, -x) # 0이 아닌 경우 추가
else : print(-heapq.heappop(pq) if len(pq) else 0) # 0인 경우 길이가 0이 아니면 pop, 맞다면 0 출력
13 changes: 13 additions & 0 deletions INSEA-99/week06/11286_절댓값_힙.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# pypy3
# 시간(ms) : 180
# 공간(KB) : 115988

import sys
import heapq
input = sys.stdin.readline

pq = []
for _ in range(int(input().strip())) :
x = int(input().strip())
if x : heapq.heappush(pq, (abs(x), x)) # 0이 아닌 경우 추가
else : print(heapq.heappop(pq)[1] if len(pq) else 0) # 0인 경우 길이가 0이 아니면 pop, 맞다면 0 출력
13 changes: 13 additions & 0 deletions INSEA-99/week06/1927_최소_힙.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# pypy3
# 시간(ms) : 164
# 공간(KB) : 114132

import sys
import heapq
input = sys.stdin.readline

pq = []
for _ in range(int(input().strip())) :
x = int(input().strip())
if x : heapq.heappush(pq, x) # 0이 아닌 경우 추가
else : print(heapq.heappop(pq) if len(pq) else 0) # 0인 경우 길이가 0이 아니면 pop, 맞다면 0 출력
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

가독성, 효율성, 심플함까지 3콤보.. 이거슨 코드 다이어트 교과서!

21 changes: 21 additions & 0 deletions INSEA-99/week06/2075_N번째_큰_수.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# pypy3
# 시간(ms) : 1028
# 공간(KB) : 122816
#
# 공유 :
# - int(1_000_000_000)은 약 29바이트
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

개발자 아니고 물리학 교수님 아님니까~~!???

# - 1500개 -> 약 0.05 MB
# - 1500*1500개 -> 약 77 MB


import sys
import heapq
input = sys.stdin.readline

pq = []
n = int(input().strip())
for _ in range(n):
for x in list(map(int, input().strip().split())) :
if len(pq) < n : heapq.heappush(pq, x) # 리스트가 n개 이하면 추가
else : heapq.heappush(pq, max(x, heapq.heappop(pq))) # 리스트가 n개 이상이면 리스트의 가장 작은 값보다 크다면 추가
print(heapq.nsmallest(1, pq)[0])