[20250310] BOJ / P4 / 교차 집합 크기 합 / 권혁준 #219
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/30806
🧭 풀이 시간
80분
👀 체감 난이도
✏️ 문제 설명
N개의 집합$S_1, S_2, \cdots, S_N$ 이 주어진다.$k$ 개를 골라, 고른 집합들의 교집합을 생각해보자. $a_k$ 는 집합을 고르는 가능한 모든 선택 방법에 대해 교집합의 크기를 더한 값이다.
이 집합들 중
모든$k = 1, 2, \cdots, N$ 에 대해, $a_k$ 를 $998,244,353 (=119 \times 2^{23} +1)$ 로 나눈 나머지를 구해보자.
$(998,244,353)$ 은 소수이다.
🔍 풀이 방법
[사용한 알고리즘]
각 원소$i$ 가 등장한 횟수를 $cnt[i]$ 라고 하면, 각 $k$ 에 대해 $a_k$ 에 $C(cnt[i], k)$ 만큼 더해지는 것을 알 수 있다.
모든 원소에 대해 저 값을 구해서$a_k$ 를 관리하면 된다.
구하는 데 걸리는 시간 복잡도는 원소의 등장 횟수에 비례하는데, 결국$O(\sum(|S|))$ 정도이기 때문이다.
⏳ 회고
식은 10분만에 도출했는데 시간복잡도가 당연히$O(N^2)$ 일 거라 생각하고 고민만 하다가 끝났다.
풀이를 보고 생각해보니, 각 원소가 등장한 횟수에 포커스를 맞췄으면 금방 해결했을 것 같은데 아쉽다.
더 집중해야 할 듯