-
Notifications
You must be signed in to change notification settings - Fork 0
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
05 우선순위큐 #2
Open
kjm3757
wants to merge
5
commits into
main
Choose a base branch
from
05_우선순위큐
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "05_\uC6B0\uC120\uC21C\uC704\uD050"
Open
05 우선순위큐 #2
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import heapq | ||
import sys | ||
input = sys.stdin.readline | ||
|
||
n = int(input()) | ||
|
||
heap = [] | ||
|
||
for _ in range(n): | ||
a = list(map(int, input().split())) | ||
|
||
if a[0] == 0: | ||
if len(heap) > 0: | ||
print(-heap[0]) | ||
heapq.heappop(heap) | ||
|
||
else: | ||
print(-1) | ||
|
||
else: | ||
for i in range(1, len(a)): | ||
heapq.heappush(heap, -a[i]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import heapq | ||
import sys | ||
input = sys.stdin.readline | ||
|
||
n = int(input()) | ||
|
||
lheap = [] | ||
rheap = [] | ||
|
||
for i in range(n): | ||
num = int(input()) | ||
|
||
if i % 2 == 0: | ||
heapq.heappush(lheap, -num) | ||
|
||
else: | ||
heapq.heappush(rheap, num) | ||
|
||
if i > 0: | ||
if -lheap[0] > rheap[0]: | ||
l = heapq.heappop(lheap) | ||
r = heapq.heappop(rheap) | ||
|
||
heapq.heappush(lheap, -r) | ||
heapq.heappush(rheap, -l) | ||
|
||
print("result: ", -lheap[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import heapq | ||
import sys | ||
input = sys.stdin.readline | ||
|
||
N = int(input()) | ||
heap = [] | ||
|
||
for _ in range(N): | ||
num = list(map(int, input().split())) | ||
for n in num: | ||
if len(heap) < N: | ||
heapq.heappush(heap, n) | ||
else: | ||
if heap[0] < n: | ||
heapq.heappop(heap) | ||
heapq.heappush(heap, n) | ||
|
||
print(heap[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import sys | ||
input = sys.stdin.readline | ||
|
||
N = int(input()) | ||
result = 0 | ||
|
||
word = input() | ||
alpa = [0]*26 | ||
|
||
for i in range(len(word)-1): | ||
alpa[ord(word[i])-ord('A')] += 1 | ||
|
||
for _ in range(N-1): | ||
ow = input() | ||
oa = [0]*26 | ||
cnt = 0 | ||
|
||
for i in range(len(ow)-1): | ||
oa[ord(ow[i])-ord('A')] += 1 | ||
|
||
for i in range(26): | ||
if alpa[i] != oa[i]: | ||
cnt += abs(alpa[i] - oa[i]) | ||
|
||
|
||
if len(word) == len(ow): | ||
if cnt == 0 or cnt == 2: | ||
result +=1 | ||
|
||
else: | ||
if cnt == 1 and abs(len(word) - len(ow)) == 1: | ||
result += 1 | ||
Comment on lines
+26
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 문제의 핵심을 정확히 파악하셨습니다! 조건 나누기가 아주 깔끔합니다.😮 |
||
|
||
print(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import heapq | ||
def solution(jobs): | ||
answer = 0 # 작업하는데 걸린 총 소요시간 | ||
now = 0 # 현재 시간 | ||
i = 0 # 처리한 작업의 수 | ||
start = -1 # 직전에 완료한 작업의 시작 시간 | ||
heap = [] # 남은 작업 중 현재 처리 가능한 작업을 저장하는 힙 | ||
|
||
while i < len(jobs): | ||
# 현재 시점에서 처리할 수 있는 작업을 힙에 저장 | ||
for j in jobs: | ||
if start < j[0] <= now: # 작업의 요청시간이 직전에 끝낸 작업보다 크고, 현재 시간보다 작은 경우 작업이 가능힘 | ||
heapq.heappush(heap, [j[1], j[0]]) # 작업 처리 시간, 작업 요청 시간 순으로 힙에 저장 | ||
|
||
if len(heap) > 0: # 힙의 길이가 0보다 큰 경우, 힙에 처리할 작업이 남은 경우 | ||
current = heapq.heappop(heap) #current는 현재 처리 중인 작업의 정보 | ||
start = now | ||
now += current[0] | ||
answer += (now - current[1]) # 작업 요청 시간부터 작업 처리 완료 시간까지 총 소요시간 | ||
i += 1 | ||
else: # 힙의 길이가 0인 경우, 처리할 작업이 없는 경우 | ||
now += 1 | ||
|
||
answer = answer // len(jobs) # 평균 처리 시간 계산 | ||
|
||
return answer | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
알파벳 개수를 따로 저장하여 해결해 주셨네요!👍👍