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$를 복원하는 것은 쉽지 않다. 실제로 서로 다른 두 수열 $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$이 주어진다.

둘째 줄에는 다중집합인 $X$의 스펙트럼이 주어진다. 수 $d_1,\ldots,d_{\frac{n(n-1)}2}$는 비내림차순으로 나열되며 인접한 두 수 사이에는 공백 하나가 있다.

출력

먼저 가능한 $X$의 총 개수(즉, 해의 개수)를 한 줄에 출력한다. 다음으로 모든 가능한 $X$를 사전순으로, 한 줄에 하나씩 출력한다.

$Y=(y_1,\ldots,y_n)$과 $Z=(z_1,\ldots,z_n)$을 두 해라고 하자. $1\le k\le n$인 어떤 인덱스 $k$에 대해 $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\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.