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

[2023-10-13] wooyeol #332#333

Merged
zsmalla merged 2 commits into
mainfrom
wooyeol-#332
Mar 18, 2024
Merged

[2023-10-13] wooyeol #332#333
zsmalla merged 2 commits into
mainfrom
wooyeol-#332

Conversation

@Woo-Yeol
Copy link
Copy Markdown
Member

@Woo-Yeol Woo-Yeol commented Oct 11, 2023

PR Summary

2048 (Easy)
https://www.acmicpc.net/problem/12100

풀이시간
23:23 ~ 24:14(49분)
풀이 참조 : https://jeongchul.tistory.com/667

문제 조건
1 <= N <=20

시간 복잡도 : O(N^3 * 4 * 4 ^ 5)
O(32,768,000)

접근법
무슨 알고리즘으로 풀이 할 수 있을까? -> 시뮬레이션(백 트래킹)

  • 시뮬레이션을 위한 함수들을 선언해주었습니다.
  1. swipe : 한 행 혹은 칼럼의 값 중 0이 아닌 값들을 queue에 넣는 역할을 수행합니다 -> 한 쪽으로 쓸기
  2. merge : queue에 들어있는 값들을 모두 검사하며 동일한 값이 두 번 나오면 합치고 다른 값이 나온다면 다른 칸에 값 채우기
  3. turn : 한 번의 턴을 의미하며 상하우좌를 기준으로 입력받은 방향으로 swipe 후 merge를 진행합니다.
  4. dfs : 백 트래킹 기법을 통해 5번의 연산 후 최대 값을 찾습니다.

@Woo-Yeol Woo-Yeol self-assigned this Oct 11, 2023
@Woo-Yeol Woo-Yeol linked an issue Oct 11, 2023 that may be closed by this pull request
@Woo-Yeol Woo-Yeol removed the request for review from limstonestone October 11, 2023 15:21
@Woo-Yeol Woo-Yeol added the BOJ label Oct 11, 2023
Copy link
Copy Markdown
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.

swife와 merge 과정을 별도의 자료구조(queue)를 두어 보다 편리하게 구현하신 점이 인상깊었던 풀이었습니다. 메모리가 넉넉하다면 이렇게 별도 자료구조를 활용하는 습관을 두면 좋을 것 같아요!
또한 이렇게 솔루션 코드를 길게 작성해야 하는 문제일수록 메서드별로 docstring을 달아놓으면 좋을 것 같다는 생각이 들었습니다. 코테에서는 시간이 남으면 꼭 권장드립니다~

무슨 알고리즘으로 풀이 할 수 있을까? -> 시뮬레이션(백 트래킹)

- 시뮬레이션을 위한 함수들을 선언해주었습니다.
1. swipe : 한 행 혹은 칼럼의 값 중 0이 아닌 값들을 queue에 넣는 역할을 수행합니다 -> 한 쪽으로 쓸기
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

저는 이걸 matrix 내부에서 while문으로 케이스에 따라 변환해서 구현했는데, 이렇게 구현하면 훨씬 쉽게 구현할 수 있다는 인사이트를 얻어갑니다..! 메모리 조건도 널널한데 이렇게 해볼 생각을 못했네요..! 아주 좋은 아이디어 같습니다.

board[x][y] = value


def turn(direct):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

이 부분이 코드 라인 측면에서의 최적화가 굉장히 잘 되었지만 가독성 측면에서 이해하기 어려운 부분이 많았던 것 같습니다. 코테에서는 메서드별로 docstring을 달아놓으시면 혹시 면접때 해당 코드를 참고하게 되더라도 금방 다시 리마인드 하기 편할 것 같아요!

@zsmalla zsmalla merged commit ab6a8cb into main Mar 18, 2024
@zsmalla zsmalla deleted the wooyeol-#332 branch March 18, 2024 10:06
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] 2048 (Easy)

2 participants