[20251106] BOJ / G1 / XOR Hashing / 권혁준#1333
Merged
ShinHeeEul merged 1 commit intomainfrom Nov 6, 2025
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/26653
🧭 풀이 시간
20분
👀 체감 난이도
✏️ 문제 설명
2차원 평면에서 좌표값의 범위가 0 이상 2^N 미만에 속하도록 M개의 점을 균일한 확률로 뽑는다.
점 (x,y)의 해시 값을 x와 y의 xor값으로 정할 때, M개의 점 중 같은 해시 값을 가진 쌍이 존재할 확률을 구해보자.
🔍 풀이 방법
어떤 점을 골라도 xor값은 항상 0 이상 2^N 미만이기 때문에,
비둘기집 원리에 의해 M > 2^N인 경우에는 같은 값이 항상 존재하게 된다. -> 1 출력이제부터는 M <= 2^N인 경우만 고려한다.
점을 하나 골랐을 때 xor 값이 i일 확률을 f(i)라고 하면, f(0)부터 f(2^N - 1)까지 모두 동일하다.
그래서 답은 1 - (xor 값이 모두 다를 확률)로 구했다.
xor값이 모두 다를 확률은 (2^N)개의 점 중에서 서로 다른 점 M개를 뽑을 확률이니까 permutation(2^N, M) / 2^NM이 된다.
분수에 대한 나머지 연산은
페르마의 소정리와분할 정복 거듭제곱을 이용해서 처리해줬다.⏳ 회고
ez