[20250909] BOJ / P2 / Double Up 2 / 권혁준 #852
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/32692
🧭 풀이 시간
70분
👀 체감 난이도
✏️ 문제 설명
길이 N인 배열 A와 정수 M이 주어진다.
이 배열에 작업을 원하는 만큼 수행할 수 있다.
작업을 모두 끝낸 뒤, 배열에서 가장 많이 등장하는 수의 등장 횟수 최댓값과 그 상태로 만들기 위한 작업의 최소 횟수를 구해보자.
🔍 풀이 방법
M이 백만까지라서, 정점 번호가 0 ~ M-1인 그래프로 모든 작업을 표현했다.
이 그래프에서 방향성을 뺐을 때 같은 컴포넌트에 속한다면 모두 같은 수로 만들어줄 수 있다.
-> 컴포넌트에 존재하는 수의 최대 개수에 대해, 작업 횟수를 최소로 만들어주면 된다.
위상 정렬로 사이클에 도달할 때까지 작업 횟수를 계속 쌓아간다.
사이클에 모인 수의 개수에 따라서 최솟값을 구해줬다.
⏳ 회고
사이클에 도달하지 않고도 모두 모일 수 있는 경우를 생각하지 못했다.