Codeforces Round 947 (Div. 1 + Div. 2)
F
Set
Codeforces
2600
原题
← EG →
翻译中…

Define the binary encoding of a finite set of natural numbers $T \subseteq \{0,1,2,\ldots\}$ as $f(T) = \sum\limits_{i \in T} 2^i$. For example, $f(\{0,2\}) = 2^0 + 2^2 = 5$ and $f(\{\}) = 0$. Notice that $f$ is a bijection from all such sets to all non-negative integers. As such, $f^{-1}$ is also defined.

翻译中…

You are given an integer $n$ along with $2^n-1$ sets $V_1,V_2,\ldots,V_{2^n-1}$.

翻译中…

Find all sets $S$ that satisfy the following constraint:

翻译中…
  • $S \subseteq \{0,1,\ldots,n-1\}$. Note that $S$ can be empty.
  • For all non-empty subsets $T \subseteq \{0,1,\ldots,n-1\}$, $|S \cap T| \in V_{f(T)}$.
翻译中…

Due to the large input and output, both input and output will be given in terms of binary encodings of the sets.

翻译中…

Input

翻译中…

The first line of input contains a single integer $n$ ($1 \leq n \leq 20$).

翻译中…

The second line of input contains $2^n-1$ integers $v_1,v_2,\ldots,v_{2^n-1}$ ($0 \leq v_i \lt 2^{n+1}$) — the sets $V_i$ given in their binary encoding where $V_i = f^{-1}(v_i)$.

翻译中…

Output

翻译中…

The first line of output should contain an integer $k$ indicating the number of possible $S$.

翻译中…

In the following $k$ lines, you should output $f(S)$ for all possible $S$ in increasing order.

翻译中…

Note

翻译中…

In the first test case, one possible $S$ is $f^{-1}(3) = \{0,1\}$. All the non-empty subsets $T \subseteq \{0,1,2\}$ and the corresponding $|S \cap T|$, $f(T)$ and $V_f(T)$ are as follows:

翻译中…

$T$$|S\cap T|$$f(T)$$V_{f(T)}$$\{0\}$$1$$1$$\{0,1,2,3\}$$\{1\}$$1$$2$$\{0,1,2,3\}$$\{2\}$$0$$4$$\{0,1,2,3\}$$\{0,1\}$$2$$3$$\{0,1,2,3\}$$\{0,2\}$$1$$5$$\{0,1,2,3\}$$\{1,2\}$$1$$6$$\{0,1,2,3\}$$\{0,1,2\}$$2$$7$$\{2,3\}$

翻译中…

样例

Input #1
3
15 15 15 15 15 15 12
Output #1
4
3
5
6
7
InputCopy OutputCopy
Input #2
5
63 63 63 63 6 63 63 63 63 63 63 5 63 63 63 63 63 63 8 63 63 63 63 2 63 63 63 63 63 63 63
Output #2
1
19
InputCopy OutputCopy
题目信息
题号
1975F
时间限制
2 s
内存限制
512 MB
标签
位运算
暴力
组合数学
DFS 及类似
分治
动态规划
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。