Skip to content
This repository was archived by the owner on Mar 18, 2024. It is now read-only.

[2023-09-13] jisu #207 #227

Merged
merged 2 commits into from
Sep 14, 2023
Merged

[2023-09-13] jisu #207 #227

merged 2 commits into from
Sep 14, 2023

Conversation

zsmalla
Copy link
Contributor

@zsmalla zsmalla commented Sep 13, 2023

PR Summary

풀이 시작 : 2023-09-13 13:44

제한 사항

  • N <= 200,000 이므로, O(NlogN) 알고리즘을 설계해야 한다.

풀이

  • 일단 강의 시작 순서대로 주어진다는 조건이 없으므로 정렬 O(NlogN)
  • 모든 배치된 강의실 중 가장 빨리 끝나는 강의실보다 현재 진행되어야 하는 강의가 더 빠르면 강의실을 추가해야 함
    • 강의가 끝나는 시간을 담은 heap으로 강의실 배정 리스트를 관리한다.
    • 모든 강의를 순회하며 해당 강의의 시작하는 시간이 가장 빨리 끝나는 강의실(heap의 root)의 끝나는 시간보다 더 빠른지 체크
      • 더 빠르다면 힙에 해당 강의의 끝나는 시간 삽입 : 강의실을 추가한다는 의미
      • 가장 빨리 끝나는 강의실의 강의가 더 빨리 끝난다면 heappop 후, 삽입 : 해당 강의실에 강의를 교체한다는 의미
    • 순회 : O(N), heappush: O(logN) -> O(NlogN)
  • 최종적으로 O(2NlogN)으로 풀이 가능
    풀이 완료 : 2023-09-13 14:50 (1시간 6분 소요)

@zsmalla zsmalla added the BOJ label Sep 13, 2023
@zsmalla zsmalla self-assigned this Sep 13, 2023
@zsmalla zsmalla linked an issue Sep 13, 2023 that may be closed by this pull request
@zsmalla zsmalla changed the title Create 강의실 배정 jisu.py [2023-09-13] jisu #207 Sep 13, 2023
Copy link
Member

@Woo-Yeol Woo-Yeol left a comment

Choose a reason for hiding this comment

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

전체적으로 코드가 많이 최적화 되어있다고 생각이 들었습니다! 고생하셨습니다 지수님! 군더더기 없이 필요한 연산만 있는 것 같아서 피드백은 따로 없을 것 같습니다!

assigned = [] # min heap으로 사용

for st, en in classes:
if not assigned or assigned[0] > st:
Copy link
Contributor

Choose a reason for hiding this comment

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

처음 강의실 배정을 무조건 가장 일찍 시작하는 강의로 설정해둔 것 빼고 동일한 로직 같아요!! 고생하셨어요 지수님👍👍👍

Copy link
Contributor

Choose a reason for hiding this comment

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

마찬가지로 수민님처럼 맨 처음에 push 수행을 먼저 했다면 조건문이 조금 더 깔끔해지긴 했겠네요!
물론 지금도 깔끔하지만요!!
고생하셨습니다!

@zsmalla zsmalla merged commit 41945ca into main Sep 14, 2023
@zsmalla zsmalla deleted the jisu-#207 branch September 14, 2023 13:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BOJ] 강의실 배정
4 participants