Skip to content

Commit

Permalink
Merge pull request #37 from AlgoLeadMe/11-pu2rile
Browse files Browse the repository at this point in the history
11-pu2rile
  • Loading branch information
pu2rile authored Aug 5, 2024
2 parents 5538bc9 + 722e7b7 commit b1afacd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Binary file modified pu2rile/.DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion pu2rile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
| 7μ°¨μ‹œ | 2024.05.10 | μ™„μ „ 탐색 μ•Œκ³ λ¦¬μ¦˜ | [μ˜ν™”κ°λ… 숌](https://www.acmicpc.net/problem/1436) | [#26](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/25#issue-2289086909)
| 8μ°¨μ‹œ | 2024.05.14 | 그리디 μ•Œκ³ λ¦¬μ¦˜ | [νŒ”](https://www.acmicpc.net/problem/1105) | [#28](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/28#issue-2295901384)
| 9μ°¨μ‹œ | 2024.05.27 | κ΅¬ν˜„ | [μ˜€λŠ˜λ„ μ‘Œλ‹€](https://www.acmicpc.net/problem/14582) | [#29](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/29#issue-2320060288)
| 10μ°¨μ‹œ | 2024.07.11 | μŠ€νƒ | [ν™”ν•™μ‹λŸ‰](https://www.acmicpc.net/problem/2257) | [#35](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/35#issue-2403173169)
| 10μ°¨μ‹œ | 2024.07.11 | μŠ€νƒ | [ν™”ν•™μ‹λŸ‰](https://www.acmicpc.net/problem/2257) | [#35](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/35#issue-2403173169)
| 11μ°¨μ‹œ | 2024.07.13 | μš°μ„ μˆœμœ„ 큐 | [κ°•μ˜μ‹€](https://www.acmicpc.net/problem/1374) | [#37](https://github.com/AlgoLeadMe/AlgoLeadMe-10/pull/37#issue-2406937336)
25 changes: 25 additions & 0 deletions pu2rile/μš°μ„ μˆœμœ„ 큐/κ°•μ˜μ‹€.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import heapq
import sys

n = int(sys.stdin.readline())

heap = [] # λͺ¨λ“  κ°•μ˜μ˜ μ‹œμž‘ μ‹œκ°„κ³Ό μ’…λ£Œ μ‹œκ°„μ„ μ €μž₯ν•  μ΅œμ†Œ νž™
q = [] # ν˜„μž¬ μ‚¬μš© 쀑인 κ°•μ˜μ‹€μ˜ μ’…λ£Œ μ‹œκ°„μ„ μ €μž₯ν•  μ΅œμ†Œ νž™

# 주어진 κ°•μ˜ 수만큼 λ°˜λ³΅ν•˜λ©΄μ„œ κ°•μ˜ 정보λ₯Ό μž…λ ₯λ°›μ•„ μ΅œμ†Œ νž™μ— μ €μž₯
for _ in range(n):
num, start, end = map(int, sys.stdin.readline().split())
heapq.heappush(heap, [start, end, num])

# 첫 번째 κ°•μ˜λ₯Ό μ΅œμ†Œ νž™μ—μ„œ κΊΌλ‚΄μ„œ ν•΄λ‹Ή κ°•μ˜μ˜ μ’…λ£Œ μ‹œκ°„μ„ λ‹€λ₯Έ νž™μ— μ €μž₯
start, end, num = heapq.heappop(heap)
heapq.heappush(q, end)

while heap:
start, end, num = heapq.heappop(heap)
# κ°€μž₯ 빨리 λλ‚˜λŠ” κ°•μ˜μ‹€μ˜ μ’…λ£Œ μ‹œκ°„μ΄ ν˜„μž¬ κ°•μ˜μ˜ μ‹œμž‘ μ‹œκ°„λ³΄λ‹€ μž‘κ±°λ‚˜ κ°™μœΌλ©΄ μ’…λ£Œ μ‹œκ°„μ„ μ΅œμ†Œ νž™μ—μ„œ 제거
if q[0] <= start:
heapq.heappop(q)
heapq.heappush(q, end) # ν˜„μž¬ κ°•μ˜μ˜ μ’…λ£Œ μ‹œκ°„μ„ μ΅œμ†Œ νž™μ— μΆ”κ°€

print(len(q)) # μ΅œμ†Œ νž™ q의 크기가 ν•„μš”ν•œ κ°•μ˜μ‹€μ˜ 수

0 comments on commit b1afacd

Please sign in to comment.