[20250725] BOJ / P4 / Four XOR / 권혁준 #542
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/21099
🧭 풀이 시간
90분
👀 체감 난이도
✏️ 문제 설명
수열에서 원소 네 개를 골라 XOR한 값이 0이 될 수 있는지 판별하기
🔍 풀이 방법
원소 네 개를 a, b, c, d라고 하면, a^b^c^d = 0이어야 한다.
이항하면 a^b = c^d여야 한다.
즉, 두 수의 xor이 같은 경우가 두 개 이상 존재해야 한다는 이야기다.
두 수의 xor로 가능한 경우는 단순하게 생각했을 땐 N^2개 정도 나오겠지만, xor의 성질 때문에 실제로는 131072개 뿐이다.
그래서 N >= 1000을 넘어가면, 두 수의 xor값이 겹치는 경우가 항상 존재하게 된다.
-> 그냥 Yes 출력하고 리턴
N < 1000인 경우만 O(N^2)으로 두 수 xor을 모두 구해 2개 이상 존재하는지 확인한다.
⏳ 회고
N을 저런 식으로 줄이는 건 처음 본다...