Skip to content

Commit 58b35af

Browse files
authored
Merge pull request #19 from team-mate-algorithm/INSEA-99/week06
Insea 99/week06
2 parents d8b5cb5 + 4e4be95 commit 58b35af

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# pypy3
2+
# 시간(ms) : 164
3+
# 공간(KB) : 10604
4+
5+
import sys
6+
import heapq
7+
input = sys.stdin.readline
8+
9+
pq = []
10+
for _ in range(int(input().strip())) :
11+
x = int(input().strip())
12+
if x : heapq.heappush(pq, -x) # 0이 아닌 경우 추가
13+
else : print(-heapq.heappop(pq) if len(pq) else 0) # 0인 경우 길이가 0이 아니면 pop, 맞다면 0 출력
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# pypy3
2+
# 시간(ms) : 180
3+
# 공간(KB) : 115988
4+
5+
import sys
6+
import heapq
7+
input = sys.stdin.readline
8+
9+
pq = []
10+
for _ in range(int(input().strip())) :
11+
x = int(input().strip())
12+
if x : heapq.heappush(pq, (abs(x), x)) # 0이 아닌 경우 추가
13+
else : print(heapq.heappop(pq)[1] if len(pq) else 0) # 0인 경우 길이가 0이 아니면 pop, 맞다면 0 출력

INSEA-99/week06/1927_최소_힙.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# pypy3
2+
# 시간(ms) : 164
3+
# 공간(KB) : 114132
4+
5+
import sys
6+
import heapq
7+
input = sys.stdin.readline
8+
9+
pq = []
10+
for _ in range(int(input().strip())) :
11+
x = int(input().strip())
12+
if x : heapq.heappush(pq, x) # 0이 아닌 경우 추가
13+
else : print(heapq.heappop(pq) if len(pq) else 0) # 0인 경우 길이가 0이 아니면 pop, 맞다면 0 출력
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# pypy3
2+
# 시간(ms) : 1028
3+
# 공간(KB) : 122816
4+
#
5+
# 공유 :
6+
# - int(1_000_000_000)은 약 29바이트
7+
# - 1500개 -> 약 0.05 MB
8+
# - 1500*1500개 -> 약 77 MB
9+
10+
11+
import sys
12+
import heapq
13+
input = sys.stdin.readline
14+
15+
pq = []
16+
n = int(input().strip())
17+
for _ in range(n):
18+
for x in list(map(int, input().strip().split())) :
19+
if len(pq) < n : heapq.heappush(pq, x) # 리스트가 n개 이하면 추가
20+
else : heapq.heappush(pq, max(x, heapq.heappop(pq))) # 리스트가 n개 이상이면 리스트의 가장 작은 값보다 크다면 추가
21+
print(heapq.nsmallest(1, pq)[0])

0 commit comments

Comments
 (0)