QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#960. 输出限制超出

Statistics

我们都知道对于任何 $0 \le k \le n$,$\binom{n}{k} = \frac{n \cdot (n-1) \cdot \dots \cdot (n-k+2) \cdot (n-k+1)}{1 \cdot 2 \cdot \dots \cdot (k-1) \cdot k}$ 都是一个整数。如果我们能通过在分子和分母的因子之间建立匹配来证明这一点,那不是很好吗?

让我们构建一个二分图,每一侧各有 $k$ 个顶点。左侧的第 $i$ 个顶点对应分子中的因子 $(n + 1 - i)$,右侧的第 $j$ 个顶点对应分母中的因子 $j$。当且仅当 $j$ 整除 $(n + 1 - i)$ 时,存在一条边 $i - j$。如果该二分图中存在完美匹配,则称数字 $k$ 对于 $n$ 是可证明的。

给定 $n$,检查对于每个满足 $0 \le k \le n$ 的 $k$,$k$ 是否对于 $n$ 是可证明的。

输入格式

仅一行,包含一个整数 $n$ ($0 \le n \le 10^{18}$)。

输出格式

输出一个长度为 $(n + 1)$ 的字符串,由 '0' 和 '1' 组成。当且仅当 $k$ 对于 $n$ 是可证明的时,第 $(k + 1)$ 个字符应为 '1'。

你认为这会导致输出超限(Output Limit Exceeded)吗?嗯……好吧,让我们压缩这个字符串。

令 $s_0 = \text{“0”}$ 且 $s_1 = \text{“1”}$。你可以定义 $s_2, s_3, \dots, s_t$。字符串 $s_i$ 应为若干先前定义的字符串的拼接。形式化地,$\forall i(2 \le i \le t) : s_i = s_{j_1} + s_{j_2} + \dots + s_{j_{k_i}}$,其中 $1 \le k_i$,且 $\forall r(1 \le r \le k_i) : j_r < i$。字符串 $s_t$ 应为问题的答案。

在第一行输出一个整数 $t$ ($2 \le t \le 500$)。

在接下来的 $t - 1$ 行中,输出 $s_i$ 的描述。每个描述应具有形式 $k_i \ j_1 \ j_2 \ \dots \ j_{k_i}$,其中 $1 \le k_i$ 且 $0 \le j_r < i$。

所有描述的总长度不应超过 $10\,000$:$\sum_{i=2}^t k_i \le 10\,000$。

我们可以证明,对于所有合法的测试用例,都存在一种满足所有限制的构造答案字符串的方法。如果有多种可能的方法,输出其中任意一种即可。注意,你不需要最小化 $t$ 或所有描述的总长度。

样例

样例输入 1

1

样例输出 1

2
2 1 1

样例输入 2

0

样例输出 2

2
1 1

样例输入 3

7

样例输出 3

4
2 1 1
4 1 2 0 0
3 3 1 2

说明

在第三个样例中:$s_2 = s_1 + s_1 = \text{“1”} + \text{“1”} = \text{“11”}$,$s_3 = s_1 + s_2 + s_0 + s_0 = \text{“1”} + \text{“11”} + \text{“0”} + \text{“0”} = \text{“11100”}$,$s_4 = s_3 + s_1 + s_2 = \text{“11100”} + \text{“1”} + \text{“11”} = \text{“11100111”}$。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#320EditorialOpen题解jiangly2025-12-14 07:04:34View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.