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/33616
🧭 풀이 시간
40분
👀 체감 난이도
✏️ 문제 설명
정수 a, b가 있다.
여기에 어떤 양의 정수 x를 골라 두 가지 종류의 조작을 할 수 있다.
a와 b를 같게 만들 수 있는지 판별하고, 가능하다면 최소 조작 횟수와 조작 명령을 직접 출력해보자.
🔍 풀이 방법
[사용한 알고리즘]
우선, 저 xor연산에서$a \oplus b = (a \wedge b) - (a \vee b) = (a+b) - 2(a \vee b)$ 이다.
만약 조작 1회만으로 같게 할 수 있다면, 어떤 수$x$ 에 대해
$a \oplus x = b + x$ 가 된다. (일반성을 잃지 않고, a > b라 가정)
위 식으로 고쳐쓰면
$a + x - 2(a \vee x) = b + x$
$a-b = 2(a \vee x)$ 가 된다.$x = (a-b)/2$ 가 되고, 유효성만 확인해주면 된다.
그래서,
만약 조작 1회만으로 안 된다면, 유효한 모든 경우에 대해 2회 만에 항상 가능하다.$a > b$ 라 하면,
$x = (b-a)/2$ 라 두고 같은 조작을 2회 시행하면 항상 둘이 같아진다.
마찬가지로
불가능한 경우는 바로 저 x값이 정수가 아닌 경우가 된다.
⏳ 회고
너무 어렵다 비트