QOJ.ac

QOJ

Time Limit: 5 s Memory Limit: 1024 MB Total points: 100

#3136. スペクトル

Statistics

$X=(x_1,x_2,\ldots,x_n)$ を、要素がすべて異なる整数列とします。$X$ のスペクトルを $\operatorname{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)$ なら、$\operatorname{spec}(X)=\{1,1,3,4,4,5\}$ です。

$X$ が与えられたとき、$\operatorname{spec}(X)$ を求めるのは簡単です。しかし、$\operatorname{spec}(X)$ から $X$ を復元するのは簡単ではありません。実際、異なる2つの列 $X$ と $Y$ に対して $\operatorname{spec}(X)=\operatorname{spec}(Y)$ となることがあります。例えば、$\operatorname{spec}(0,7,20)=\{7,13,20\}=\operatorname{spec}(0,13,20)$ です。入力で指定されたスペクトルと $\operatorname{spec}(X)$ が等しくなる、すべての可能な $X$ を復元してください。

入力

テストケースの最初の行には、整数列 $X$ の長さである数 $n$ が与えられます。

2行目には、多重集合である $X$ のスペクトルが与えられます。数 $d_1,\ldots,d_{\frac{n(n-1)}2}$ は非減少順に並び、隣り合う2つの数の間には区切りとして空白が1つあります。

出力

まず、可能な $X$ の総数(解の数)を1行に出力してください。次に、可能な $X$ をすべて辞書順で、1行に1つずつ出力してください。

$Y=(y_1,\ldots,y_n)$ と $Z=(z_1,\ldots,z_n)$ を2つの解とします。ある添字 $k$($1\le k\le n$)について $y_k<z_k$ であり、すべての $1\le j<k$ について $y_j=z_j$ である場合、かつその場合に限り、$Y$ が $Z$ より前になります。例えば、列 $Y=(0,7,20)$ は $y_2<z_2$($7<13$)かつ $y_1=z_1$ なので、辞書順で $Z=(0,13,20)$ より前になります。各 $X$ の要素は昇順で出力し、隣り合う2つの数の間に空白を1つ入れてください。

制約

  • $2\le n\le62$.

  • $0<d_1\le d_2\le\cdots\le d_{\frac{n(n-1)}2}$.

  • 出力は、$1\le i\le n$ について $0\le x_i\le999$、および $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.