-
Notifications
You must be signed in to change notification settings - Fork 1
[한종욱-17주차 알고리즘 스터디] #76
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
Open
Ukj0ng
wants to merge
88
commits into
main
Choose a base branch
from
ukjong/week-17
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.
Open
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🚀 싸피 15반 알고리즘 스터디 17주차 [한종욱]
📌 문제 풀이 개요
✅ 문제 해결 여부
💡 풀이 방법
문제 1: 피아의 아틀리에 신비한 대회의 연금술사
문제 난이도
Gold 1
문제 유형
브루트포스, 구현
접근 방식 및 풀이
여러 조건을 완전 탐색했습니다.
1번 조건을 계산하기 위해 3중 for문으로 작성했습니다.
2, 3번 조건은 서로 영향을 미치므로 6중 for문으로 작성했습니다.
이렇게 작성한 이유는 각 재귀를 사용한 DFS보다 for문이 더 공간적으로 효율적이라고 생각했습니다.
주의사항으로 매번 map을 초기화하고 사용하니 시간초과가 발생했습니다. 이를 해결하기 위해 기존에 사용한 map을 초기화할 때, new를 사용하지 않고, 초기값들을 재할당하는 방식을 사용했습니다.
시간복잡도:$O(n^{3} \times 4^{6})$
문제 2: 새로운 게임 2
문제 난이도
Gold 2
문제 유형
구현
접근 방식 및 풀이
문제에서 제시한 조건을 그대로 구현했습니다.
주의사항은 빨간색에 도착할 경우, 말이 이동하고 쌓여있는 순서를 전부 뒤집는게 아니라 이동한 말을 포함해 그 위로 쌓인 말들의 순서만 뒤집는 것입니다. 문제를 제대로 읽지 않아 해당 칸의 말을 전부 뒤집어 틀렸었습니다.
또, 각 말이 칸에 쌓여있을 때 몇 번째로 쌓여있는지에 대한 index를 기반으로 문제를 구현했는데, 다음 칸이 파란색일 때 반대로 이동할 경우 index 갱신을 하지 않았었습니다.
시간복잡도:$O(1000 \times k^{2})$
문제 3: 군사 이동
문제 난이도
Gold 3
문제 유형
kruskal, 이분 탐색, 매개 변수 탐색
접근 방식 및 풀이
저번 주의 세부문제와 거의 같은 문제였습니다. 다른 점이 있다면, PriorityQueue를 길의 너비의 내림차순을 기준으로 정렬한다는 점입니다.
문제에선 너비가 가장 좁은 길의 너비를 최대화 해야 합니다.
이분 탐색
이분 탐색을 통해 너비가 가장 좁은 길의 너비를 선택하고 이 너비로 길이 이어지는 방법을 생각했습니다.
kruskal
가장 너비가 넓은 길부터 선택하면, 두 수도가 이어졌을 때 경로 상의 병목 구간을 최대화할 수 있습니다.
시간복잡도:$O(w \times log(w))$
문제 4: 인하니카 공화국
문제 난이도
Gold 3
문제 유형
DFS, 트리
접근 방식 및 풀이
정점 1에서 시작해서 각 리프노드까지 DFS로 탐색합니다. 각 노드에서 두 가지 선택 중 최소 비용을 선택합니다.
위 두 비용을 비교해 cost에 더합니다.
시간복잡도:$O(n + m)$
문제 5: 택배
문제 난이도
Gold 1
문제 유형
그리디, 정렬
접근 방식 및 풀이
1번 마을에서 가까운 도시 기준으로 택배차를 모두 채웁니다.
다음 마을로 갈 때, 가져온 택배 중 해당 도시에 내려놔야 할 것을 내려놓습니다.
그 다음 남은 택배와 해당 도시의 택배들을 list에 모두 넣고 가까운 도시 기준으로 택배차를 모두 채웁니다.
n에 도착할 때까지 이를 반복합니다.
시간복잡도:$O(n \times m log(m))$
문제 6: 집배원 한상덕
문제 난이도
Platinum 4
문제 유형
접근 방식 및 풀이
시간복잡도:$O(n^2 \times log{n}))$
문제 7: 어항 정리
문제 난이도
Platinum 5
문제 유형
접근 방식 및 풀이
시간복잡도: O(mlogn)
문제 8: Cubeditor
문제 난이도
Gold 2
문제 유형
다익스트라
접근 방식 및 풀이
시간복잡도:$O()$