[cpp] 7차 Softeer 정기 역량 진단 1번 문제 - 자동차 테스트 #63
Merged
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.
🌁 Background
2023년 7차 Softeer 정기 역량 진단
👩💻 Contents
[7차 Softeer 정기 역량 진단] 1번 - 자동차 테스트
📝 Review Note
문제의 제약조건에서 알 수 있다싶이,
n
의 최대값이50,000
이고q
의 최대값이200,000
이다.n
이50,000
이고q
가200,000
이라면,n
개의 자동차 중 임의의 3개를 직접 골라서, 중앙값이m
이 될 수 있는 서로 다른 경우의 수를 구하는 것은O(N^3)
의 시간복잡도를 가진다. 제한시간인2초
를 넘어가기 때문에,O(N^3)
의 알고리즘으로는 풀 수 없다.이는 최소한
O(Q * log N)
의 알고리즘으로 풀어야 한다는 것을 의미한다.O(Q * log N)
의 알고리즘으로 풀기 위해서는,n
개의 자동차의 연비를 정렬한 다음 각q
에 대해m
의 인덱스를 이진 탐색으로 찾아야 한다.본 풀이와 같이 해시 테이블을 이용한
O(N * log N + Q)
알고리즘으로도 풀 수 있다.