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

[2023-09-04] sumin #162 #188

Merged
merged 2 commits into from
Sep 5, 2023
Merged

[2023-09-04] sumin #162 #188

merged 2 commits into from
Sep 5, 2023

Conversation

ksumini
Copy link
Contributor

@ksumini ksumini commented Sep 4, 2023

PR Summary

풀이시간: 50분

<input>

  • w, h: 방의 가로, 세로 (1 ≤ w, h ≤ 20)
  • 방의 정보
    • .: 깨끗한 칸
    • *: 더러운 칸
    • x: 가구
    • o: 로봇 청소기의 시작 위치
  • 더러운 칸의 개수는 10개를 넘지 않으며, 로봇 청소기의 개수는 항상 하나
  • 입력의 마지막 줄에는 0이 두 개

<solution>

  • 더러운 칸(최대 10)개의 순서를 모두 구하고(10!), 각 더러운 칸(10개)에 대해 BFS를 모두 돌리면 최악의 경우 10! * 400 * 10 = 14,515,200,000로 시간 초과
  • 따라서, 매 순열마다 BFS를 수행하지 않고 미리 시작지점과 더러운 칸들 간의 거리를 계산 = O(WH10)
  • 모든 순열을 만들어 모든 칸을 방문하는데 걸리는 시간 중 최소값을 구한다. -> 모든 순열을 구하는데 O(10! * 10)

<시간복잡도>
O(W * H * 10) + O(더러운 칸의 개수! * 더러운 칸의 개수) = 최대 36,292,000의 연산횟수

@ksumini ksumini added the BOJ label Sep 4, 2023
@ksumini ksumini requested a review from Woo-Yeol as a code owner September 4, 2023 07:54
@ksumini ksumini self-assigned this Sep 4, 2023
@ksumini ksumini requested a review from zsmalla as a code owner September 4, 2023 07:54
@ksumini ksumini linked an issue Sep 4, 2023 that may be closed by this pull request
Copy link
Contributor

@zsmalla zsmalla left a comment

Choose a reason for hiding this comment

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

주석과 코드가 깔끔해서 이해하기 어렵지 않았습니다. 고려할 점을 남겼으니 검토 부탁드리겠습니다! 고생하셨습니다 수민님!

distances = [[-1] * l for _ in range(l)] # 더러운 칸 간의 최단거리를 저장하는 2차원 배열 초기화
ok = True

for i in range(l):
Copy link
Contributor

Choose a reason for hiding this comment

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

이 메트릭스는 결국 대각선 r=c인 요소를 기준으로 대칭이 되므로, 88행에서
distances[i][j] = distances[j][i] = dist[dirty[j][0]][dirty[j][1]]
이렇게 대칭 원소까지 값을 할당하고, 이후 대칭 원소의 값은 탐색하지 않는 방향으로 탐색하면 BFS 횟수를 반으로 줄일 수 있을 것 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오 감사합니다 지수님!! 대칭성까지는 생각도 못했는데 배워갑니당~!!

Copy link
Contributor

@limstonestone limstonestone left a comment

Choose a reason for hiding this comment

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

뭐라 피드백드리기 어려울 정도로 깔끔하고 정석적으로 풀이해내신 것 같습니다 .. ㅎ
변수명, 주석들도 한 눈에 잘 들어오네요 감사합니다 ~!

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.

수민님 문제풀이도 당연히 말할 것 도 없지만 시간 복잡도 계산도 잘해주셔서 너무 감사합니다. 고생하셨습니다 수민님!

@ksumini ksumini merged commit 295aa13 into main Sep 5, 2023
@ksumini ksumini deleted the sumin-#162 branch September 5, 2023 15:01
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