This repository was archived by the owner on Mar 18, 2024. It is now read-only.
[2023-07-09] jisu #81#83
Merged
Merged
Conversation
limstonestone
approved these changes
Jul 12, 2023
Contributor
limstonestone
left a comment
There was a problem hiding this comment.
누적합을 미리 구해놓고 이진 탐색을 하는 방법도 있군요! 뭔가 이게 더 robust 하고 정석(?)적으로 풀어낸 느낌이 드네요?! 풀이 감사합니당~!
Woo-Yeol
approved these changes
Jul 12, 2023
Member
There was a problem hiding this comment.
누적합에 대한 접근이 너무 인상 깊어서 좋았습니다. 저도 비슷한 접근으로 접근하였으나 앞과 뒤를 나타내는 부분에서 투 포인터로 접근을 진행하였었습니다. 하지만 다음의 방식이 더 접근 방식이 한 눈에 다가와서 좋았던 것 같습니다. 고생하였습니다!
Contributor
|
누적합과 이진탐색으로 풀이하시고, 그림도 그려주셔서 이해하기 쉬웠어요! |
ksumini
approved these changes
Jul 12, 2023
y2r1m
approved these changes
Jul 12, 2023
Contributor
y2r1m
left a comment
There was a problem hiding this comment.
그림으로 그려주셔서 한결 이해가 쉬웠습니다!! 이진 탐색으로 이렇게 구현할 수 있군요! 좋은 풀이 감사합니다~!
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
PR Summary
1시간 정도 소요
[제한조건]
5 <= len(sequence) <= 1,000,000
1 <= sequence <= 1,000
5 <= k <= 1,000,000,000
[idea]
0, 1, 2, ... i 번째 원소부터 누적합을 구한 후, 누적합이 k인 경우 찾기
이 때 기본 오름차순으로 정렬되어 있으므로 누적합은 항상 증가하는 방향이다.
또한 오름차순인 것에 힌트, 누적합이 k인 경우를 찾을 때 이진 탐색을 활용할 수 있다.
[누적합 활용]

sequence의 각 원소를 해당 원소까지의 누적 합으로 업데이트 한 후, i번째 원소 전까지의 누적합을 빼어
i번째부터의 누적합을 활용할 수 있다.
[이진 탐색]
i번째 인덱스 부터의 인덱스를 활용할 수 있다면, 오름차순으로 정렬되어있음을 활용해 k를 탐색하는 과정에서 이진 탐색(파라메트릭 서치)을 적용할 수 있다.
ISSUE NUMBER