結果
問題 | No.1963 Subset Mex |
ユーザー |
![]() |
提出日時 | 2025-06-12 20:47:21 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,488 bytes |
コンパイル時間 | 149 ms |
コンパイル使用メモリ | 81,732 KB |
実行使用メモリ | 108,012 KB |
最終ジャッジ日時 | 2025-06-12 20:48:45 |
合計ジャッジ時間 | 8,223 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 2 TLE * 1 -- * 23 |
ソースコード
import sys from collections import deque MOD = 998244353 def main(): N = int(sys.stdin.readline()) S = list(map(int, sys.stdin.readline().split())) from collections import defaultdict initial = defaultdict(int) for x in S: initial[x] += 1 visited = set() queue = deque() initial_state = tuple(sorted(initial.items())) visited.add(initial_state) queue.append(initial_state) count = 0 while queue: current = queue.popleft() current_dict = defaultdict(int) for x, cnt in current: current_dict[x] = cnt count = (count + 1) % MOD elements = list(current_dict.keys()) m = len(elements) for mask in range(1, 1 << m): subset = [] for i in range(m): if (mask >> i) & 1: subset.append(elements[i]) subset = list(subset) mex = 0 while mex in subset: mex += 1 new_dict = current_dict.copy() for x in subset: new_dict[x] -= 1 if new_dict[x] == 0: del new_dict[x] new_dict[mex] += 1 new_state = tuple(sorted(new_dict.items())) if new_state not in visited: visited.add(new_state) queue.append(new_state) print(count % MOD) if __name__ == "__main__": main()