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/1187
🧭 풀이 시간
140분
👀 체감 난이도
✏️ 문제 설명
2N - 1개(N = 2k, 1 ≤ k ≤ 10)의 정수 중 임의로 N개를 뽑았을 때, 이 합이 N으로 나누어떨어지도록 하는 N개의 수를 출력해보자.
🔍 풀이 방법
N = 2인 경우부터 보면, 3개의 수 중 2개의 수의 합이 2로 나누어떨어지는 경우를 찾아야 한다.
즉, 두 수의 합이 짝수가 되는 경우를 찾아야 하고, 이 경우는 짝수+짝수 혹은 홀수+홀수 두 경우로만 나타내어진다.
여기서 수가 총 3개이므로, 짝수/홀수 중 적어도 한 쪽은 두 개 이상 반드시 존재한다.
N = 4인 경우로 확장해보면, 7개의 수 중 4개의 수의 합이 4로 나누어떨어지는 경우를 찾아야 한다.
그러면, 4로 나눈 나머지가 0인 두 그룹 혹은 4로 나눈 나머지가 2인 두 그룹으로 나타내어질 수밖에 없다.
왜냐? 아까 위에서 3개의 수가 있다면 두 개의 수의 합이 2로 나누어 떨어지게 반드시 할 수 있다고 했었다.
근데 N = 4일 땐 총 수의 개수가 7개이고, 적어도 두 그룹이 나머지가 0 혹은 2인 두 그룹으로 반드시 나타낼 수 있기 때문이다.
이런 식으로 확장해가며 풀이를 떠올렸고,
구현할 때는 분할 정복으로 파고들며 구현했다.
⏳ 회고
너무어렵다