[20250409] BOJ / P4 / 아 또 XOR이야? / 권혁준 #304
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.
🧷 문제 링크
https://www.acmicpc.net/problem/27378
🧭 풀이 시간
56분
👀 체감 난이도
✏️ 문제 설명
정수 N, K, A, B가 주어지면, A이상 B이하의 정수 중 N과 XOR연산을 했을 때 이진수 표기에 1이 K개 등장하는 수의 개수를 구해보자.
🔍 풀이 방법
[사용한 알고리즘]
문제를 살짝 바꿔서, 함수
f(n, k, x)를1이상 x이하의 정수 중 n과 XOR연산을 했을 때 이진수 표기에 1이 k개 등장하는 수의 개수라고 하면,문제의 답은 f(N, K, B) - f(N, K, A-1)이 된다.
f를 구할 때는, 최상위 1비트의 위치를 점점 옮겨가며 0과 1의 개수를 세어주고 이항 계수로 경우의 수를 구해준다.
⏳ 회고
너무 어렵다