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.
🌱 문제번호와 링크
https://www.acmicpc.net/problem/2096
🥺 무엇을 알게 되었나요?
처음에 2차원 배열 dp를 두개(max, min)만들어서 모든 값을 메모이제이션 했더니 메모리 초과가 났다.
문제를 잘 읽어보면 메모리 제한이 4mb로 매우 적은 양이다. ..
그럼 저렇게 배열을 만들면 안된다는 건데,,
이 문제는 조금만 더 생각해보면 사실 옛날값까지 가지고 있을 필요가 없다.
그래서 굳이 2차원 배열로 모든 값을 저장하고 있지 않아도 된다.
그래서 현재 값만 maxdp, mindp에 저장해주는 걸로 바꿨다.
그리고 for문을 돌면서 현재 가장 큰값, 현재 가장 작은 값을 저 배열에 저장해줬다!
tmp배열을 만든 이유는 바로바로 maxdp, mindp에 저장해버리면 만약 0번째 자리 -> 1번째자리 계산하게 되면 0번째자리가 이미 갱신되어버린 값이기 때문에 1번째자리 값이 제대로 안나온다, , ,, 그렇기 때문에 한 줄이 모두 끝나고 나서야 값을 갱신해줘야 한다! 이때 한 줄이 끝날때까지 임시 저장소를 가지고 있으려고 tmp배열을 사용했다.