QOJ.ac

QOJ

時間限制: 5 s 記憶體限制: 1024 MB 總分: 100

#3136. 谱

统计

令 $X = (x_1, x_2, \dots, x_n)$ 为一个元素互不相同的整数序列。$X$ 的谱(spectrum),记作 $spec(X)$,是多重集 $\{|x_i - x_j| : 1 \le i < j \le n\}$。注意,多重集计算元素的重数但忽略顺序。例如,$\{1, 1, 2\}$ 和 $\{2, 1, 1\}$ 是相同的,但 $\{1, 1, 2\}$ 和 $\{1, 2\}$ 在多重集中是不同的。为简化起见,我们假设序列 $X$ 按升序排列且 $x_1 = 0$。例如,假设 $X = (0, 1, 4, 5)$,则 $spec(X) = \{1, 1, 3, 4, 4, 5\}$。给定 $X$,计算 $spec(X)$ 很简单。然而,给定 $spec(X)$,从 $spec(X)$ 恢复 $X$ 并非易事。事实上,对于两个不同的序列 $X$ 和 $Y$,可能存在 $spec(X) = spec(Y)$。例如,$spec(0, 7, 20) = \{7, 13, 20\} = spec(0, 13, 20)$。你的任务是恢复所有满足 $spec(X)$ 等于输入中给定谱的序列 $X$。

输入格式

测试用例的第一行给出一个整数 $n$,表示整数序列 $X$ 的大小。 第二行给出 $X$ 的谱,这是一个多重集,其中的数字 $d_1, \dots, d_{\frac{n(n-1)}{2}}$ 按非降序排列,两个连续数字之间用单个空格分隔。

输出格式

首先,在一行中输出所有可能的 $X$ 的总数(即解的个数)。然后,按字典序输出所有可能的 $X$,每个 $X$ 占一行。 令 $Y = (y_1, \dots, y_n)$ 和 $Z = (z_1, \dots, z_n)$ 为两个这样的解。当且仅当存在某个索引 $k$($1 \le k \le n$),使得 $y_k < z_k$ 且对于所有 $1 \le j < k$ 都有 $y_j = z_j$ 时,$Y$ 应排在 $Z$ 之前。例如,序列 $Y = (0, 7, 20)$ 应排在 $Z = (0, 13, 20)$ 之前,因为 $y_2 < z_2$(即 $7 < 13$)且 $y_1 = z_1$。对于每个 $X$,按升序打印其元素,并在两个连续数字之间用单个空格分隔。

数据范围

  • $2 \le n \le 62$
  • $0 < d_1 \le d_2 \le \dots \le d_{\frac{n(n-1)}{2}}$
  • 你的输出应满足:对于 $1 \le i \le n$,有 $0 \le x_i \le 999$ 且 $x_1 = 0$
  • 对于 $1 \le i < j \le n$,有 $x_i < x_j$

样例

样例输入 1

4
2 2 2 4 4 6

样例输出 1

1
0 2 4 6

样例输入 2

5
3 3 6 9 9 12 12 15 18 21

样例输出 2

2
0 3 12 15 21
0 6 9 18 21

样例输入 3

4
5 6 7 8 9 10

样例输出 3

0

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.