Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3-kjs254 #10

Merged
merged 2 commits into from
Feb 21, 2024
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
1 change: 1 addition & 0 deletions kjs254/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
|:----:|:---------:|:----:|:-----:|:----:|
| 1μ°¨μ‹œ | 2024.02.12 | μŠ€νƒ | [κΈ°λŠ₯개발](https://school.programmers.co.kr/learn/courses/30/lessons/42586) | [#2](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/2) |
| 2μ°¨μ‹œ | 2024.02.15 | 큐 | [ν”„λ‘œμ„ΈμŠ€](https://school.programmers.co.kr/learn/courses/30/lessons/42587) | [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/6) |
| 3μ°¨μ‹œ | 2024.02.15 | νž™ | [μ•Όκ·Ό μ§€μˆ˜](https://school.programmers.co.kr/learn/courses/30/lessons/12927) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/10) |
---
File renamed without changes.
16 changes: 16 additions & 0 deletions kjs254/νž™/μ•Όκ·Ό μ§€μˆ˜.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import heapq
def solution(n, works):
max_heap = []
for w in works:
heapq.heappush(max_heap, (-w,w))
Copy link
Collaborator

Choose a reason for hiding this comment

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

μ½”λ“œμ—μ„œ 이 뢀뢄이 잘 이해가 λ˜μ§€ μ•Šμ•˜μ—ˆμ§€λ§Œ μ„€λͺ…을 잘 ν•΄μ£Όμ…”μ„œ Max Heap을 κ΅¬ν˜„ν•˜λŠ” λ°©λ²•μ΄λΌλŠ” 것을 잘 μ•Œ 수 μžˆμ—ˆμŠ΅λ‹ˆλ‹€.
쒋은 μ„€λͺ… κ°μ‚¬ν•©λ‹ˆλ‹€.😁


for i in range(n):
max_work = heapq.heappop(max_heap)[1]-1
if max_work<0:
return 0

heapq.heappush(max_heap,(-max_work,max_work))
Comment on lines +7 to +12
Copy link
Collaborator

Choose a reason for hiding this comment

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

ii μ—μ„œ μ„€λͺ…ν•΄μ£Όμ…¨λ˜ κ²ƒμ²˜λŸΌ μ‹œκ°„ λ³΅μž‘λ„μ— λŒ€ν•΄ μ„€λͺ…ν•΄μ£Όμ‹œλ©° μ‹œκ°„λ³΅μž‘λ„κ°€ O(n)처럼 λ‚˜μ˜€λ©° μ‹œκ°„μ΄ 였래걸렀 heap을 μ΄μš©ν•˜μ—¬ μ‹œκ°„μ„ μ€„μ΄κ² λ‹€λŠ” μ „λž΅μ„ 잘 μ΄ν•΄ν•˜μ˜€μŠ΅λ‹ˆλ‹€. 쒋은 방법인것 κ°™μŠ΅λ‹ˆλ‹€.

μ €λŠ” μ²˜μŒμ— 맀 μ‹œν–‰ μ „ sort ν•˜μ—¬ 제일 큰 값을 μ°Ύμ•„ -1 ν•˜κ² λ‹€κ³  μƒκ°ν•˜μ˜€μœΌλ‚˜, 쑰금 κ³ λ―Όν•΄λ³΄λ‹ˆ μ‹œκ°„λ³΅μž‘λ„κ°€ 더 λ†’κ²Œ λ‚˜μ˜€λŠ” 것 κ°™λ„€μš”. 이 뢀뢄에 λŒ€ν•΄μ„œλ„ 제 생각이 λ§žλŠ”μ§€ ν”Όλ“œλ°±ν•΄μ£Όμ‹œλ©΄ 쒋을 것 κ°™μŠ΅λ‹ˆλ‹€.

μ œκ°€ 생각해보지 λͺ»ν–ˆλ˜ 방법인 것 κ°™μŠ΅λ‹ˆλ‹€. 쒋은 방법 κ°μ‚¬ν•©λ‹ˆλ‹€.😁

Copy link
Member Author

Choose a reason for hiding this comment

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

ii μ—μ„œ μ„€λͺ…ν•΄μ£Όμ…¨λ˜ κ²ƒμ²˜λŸΌ μ‹œκ°„ λ³΅μž‘λ„μ— λŒ€ν•΄ μ„€λͺ…ν•΄μ£Όμ‹œλ©° μ‹œκ°„λ³΅μž‘λ„κ°€ O(n)처럼 λ‚˜μ˜€λ©° μ‹œκ°„μ΄ 였래걸렀 heap을 μ΄μš©ν•˜μ—¬ μ‹œκ°„μ„ μ€„μ΄κ² λ‹€λŠ” μ „λž΅μ„ 잘 μ΄ν•΄ν•˜μ˜€μŠ΅λ‹ˆλ‹€. 쒋은 방법인것 κ°™μŠ΅λ‹ˆλ‹€.

μ €λŠ” μ²˜μŒμ— 맀 μ‹œν–‰ μ „ sort ν•˜μ—¬ 제일 큰 값을 μ°Ύμ•„ -1 ν•˜κ² λ‹€κ³  μƒκ°ν•˜μ˜€μœΌλ‚˜, 쑰금 κ³ λ―Όν•΄λ³΄λ‹ˆ μ‹œκ°„λ³΅μž‘λ„κ°€ 더 λ†’κ²Œ λ‚˜μ˜€λŠ” 것 κ°™λ„€μš”. 이 뢀뢄에 λŒ€ν•΄μ„œλ„ 제 생각이 λ§žλŠ”μ§€ ν”Όλ“œλ°±ν•΄μ£Όμ‹œλ©΄ 쒋을 것 κ°™μŠ΅λ‹ˆλ‹€.

μ œκ°€ 생각해보지 λͺ»ν–ˆλ˜ 방법인 것 κ°™μŠ΅λ‹ˆλ‹€. 쒋은 방법 κ°μ‚¬ν•©λ‹ˆλ‹€.😁

맨 처음 λ¬Έμ œμ— μ ‘κ·Όν•˜μ˜€μ„ λ•Œ μ„€λͺ…ν•΄μ£Όμ‹  방법과 같은 λ°©λ²•μœΌλ‘œ μ•„λž˜ μ½”λ“œλ₯Ό μž‘μ„±ν•΄ λ³΄μ•˜μŠ΅λ‹ˆλ‹€.

def solution(n, works):
    answer = 0
    for i in range(n):
        works.sort()
        if works[-1]:
            works[-1]-=1
    return sum([x**2 for x in works])

말 κ·ΈλŒ€λ‘œ 맀 μˆœκ°„ μ˜€λ¦„μ°¨μˆœ ν•˜μ—¬ μ΅œλŒ€κ°’μ—μ„œ 1 을 λΉΌλŠ” λ°©λ²•μž…λ‹ˆλ‹€.

정확도 λΆ€λΆ„μ—μ„œλŠ” λ§Œμ μ„ λ°›μ•˜μœΌλ‚˜ νš¨μœ¨μ„±μ—μ„œ λͺ¨λ‘ μ‹œκ°„μ΄ˆκ³Όκ°€ λœ¨λŠ” κ²°κ³Όκ°€ μžˆμ—ˆμŠ΅λ‹ˆλ‹€.

μ½”λ“œλ₯Ό μ œλŒ€λ‘œ νŒŒμ•…ν•΄ μ£Όμ…”μ„œ κ°μ‚¬ν•©λ‹ˆλ‹€ πŸ‘ πŸ‘ πŸ‘


print(max_heap)
answer = sum([x[1]**2 for x in max_heap])
return answer