結果
問題 |
No.1963 Subset Mex
|
ユーザー |
![]() |
提出日時 | 2025-03-20 20:57:19 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,805 bytes |
コンパイル時間 | 237 ms |
コンパイル使用メモリ | 81,720 KB |
実行使用メモリ | 103,632 KB |
最終ジャッジ日時 | 2025-03-20 20:57:32 |
合計ジャッジ時間 | 8,176 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 2 TLE * 1 -- * 23 |
ソースコード
from collections import defaultdict, deque from sys import stdin MOD = 998244353 def main(): N = int(stdin.readline()) S = list(map(int, stdin.readline().split())) initial = defaultdict(int) for num in S: initial[num] += 1 visited = set() queue = deque() # Initialize state as tuple of sorted elements with counts initial_tuple = frozenset(initial.items()) visited.add(initial_tuple) queue.append(initial) count = 1 # Initial state is counted while queue: current = queue.popleft() # Generate all possible non-empty subsets (in terms of set elements) elements = list(current.keys()) m = len(elements) all_subset_elements = [] from itertools import combinations for k in range(1, m + 1): for combo in combinations(elements, k): all_subset_elements.append(set(combo)) all_subset_elements.append(set()) for subset_set in all_subset_elements: if not subset_set: continue # No empty subsets allowed mex = 0 while mex in subset_set: mex += 1 new_current = defaultdict(int, current) for num in subset_set: new_current[num] -= 1 if new_current[num] == 0: del new_current[num] new_current[mex] += 1 # Create a normalized state representation normalized = frozenset(new_current.items()) if normalized not in visited: visited.add(normalized) count += 1 if count >= MOD: count -= MOD queue.append(new_current) print(count % MOD) if __name__ == '__main__': main()