Merged
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/2912
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
백설공주와 난쟁이 N명이 숲 속에 살고 있다.
i번째 난쟁이는 색이 C[i]인 모자를 쓰고 있다.
사진 한 장은 두 정수 (a,b)로 나타내지며, a번째 난쟁이부터 b번째 난쟁이까지 사진에 찍혔다는 의미이다.
사진에 찍힌 난쟁이들이 쓰고 있는 모자의 색 중 절반 이상이 같은 색이라면, 그 사진은 예쁜 사진이다.
사진이 M장 주어지면, 각각 예쁜 사진인지 아닌지 알아보자. 만약 예쁜 사진이라면, 절반이 넘는 모자의 색을 구해보자.
🔍 풀이 방법
[사용한 알고리즘]
리스트를 C+1개 만들어, 각 색상을 보유하고 있는 난쟁이의 번호를 각각의 리스트에 담아준다.
=> 찾으려는 모자 색과 사진의 구간이 정해지면, 이분 탐색으로 같은 색의 개수를 구할 수 있다.
예쁜 사진 내에 존재하는 절반이 넘는 모자를 예쁜 모자라고 하자.
예쁜 사진에서 난쟁이를 랜덤으로 한 명 골랐을 때 그 난쟁이의 모자가 예쁜 모자가 아닐 확률은$q < \dfrac{1}{2}$ 이다.$x$ 명 골랐을 때 예쁜 모자가 하나도 나오지 않을 확률은 $q^x < \dfrac{1}{2^x}$ 이다.
-> 예쁜 사진에서 난쟁이를 랜덤으로
따라서, 어떤 사진에서 100번 랜덤 추출해서 예쁜 모자가 나오지 않았다면, 그 사진은 예쁜 사진이 아니라고 봐도 무관하다.
-> 총 시간복잡도는$O(100M\log{N})$ 이다.
⏳ 회고
말도 안 되는 것 같다