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/31930
🧭 풀이 시간
180분
👀 체감 난이도
✏️ 문제 설명
N개의 지점 중 서로 다른 두 지점에 보물이 묻혀있다. (2 <= N <= 92)
범위 [l, r]을 지정하여 해당 범위에 보물이 정확히 하나만 존재하는지 채점 시스템에게 질문할 수 있다.
질문을 47회 이하로 해서 이 두 지점을 알아내보자.
🔍 풀이 방법
우선 N <= 47이면 l = r인 질문을 N번 던져서 해결할 수 있다.
그렇지 않은 경우, 어떤 범위 [l, r]에 대한 질문의 답이 만약 O라면, [l, r]에서 이분 탐색으로 보물의 지점 하나를 찾을 수 있다.
윈도우의 너비를 (N+2)/2로 세팅하고 1번 지점부터
슬라이딩 윈도우로 질문을 날린다.첫 질문을 [start, end]라고 하자.
아래 세 가지 경우로 나뉘게 된다.
이 경우는 O가 나온 범위인 [start, end]에서 이분 탐색을 하고, 그 외의 지점들 [end+1, N]에 대한 답 또한 O라는 의미니까 거기서 이분 탐색으로 답을 찾는다.
이전의 X들은 두 가지 경우 중 하나를 의미한다.
2-1. X들이 두 보물을 모두 포함하던 경우
2-2. X들이 보물을 포함하지 않던 경우
O를 답한 질문의 범위를 [s,e]라고 하자.
[e,e]에 질문을 날려서 만약 X였다면 위의 2-1에 해당하고, O였다면 2-2에 해당한다.
2-1인 경우에는 반드시 s-1에 보물이 존재하고, 나머지 보물은 [s,end]에 존재한다.
2-2인 경우에는 반드시 e에 보물이 존재하고, 나머지 보물은 [e+1, N]에 존재한다.
각각 이분 탐색으로 찾을 수 있다.
이 때는 반드시 end, end-1 두 지점이 답이 된다.
윈도우의 너비를 (N+2)/2로 했을 때, 모든 질문이 겹치게 되는 지점이 하나 혹은 두 개이고, 모두 겹치는 지점이 하나면 애초에 3번 경우가 될 수 없기 때문이다.
이렇게 하면 N = 92이고, 보물이 (44, 45) 혹은 (44, 46)에 있는 경우를 제외하면 모든 케이스에서 맞는다.
저런 특정 경우에서는 질문 횟수가 48번이라 틀리게 되는데, 논리적으로 가능한 모든 경우를 다 따져보면 질문 횟수를 1회 줄일 수 있다.
⏳ 회고
최근 본 문제들 중에 젤 이상하고 어려웠음