QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 2048 MB 總分: 100

#15134. 寻找丢失的数组

统计

在一个被遗忘的国度里,一群冒险者在古老图书馆的深处偶然发现了一卷神秘的卷轴。这些卷轴记载着一个控制着该国度魔法的强大数值数组的秘密。然而,随着时间的流逝,卷轴已经受损,只剩下了残卷。具体来说,冒险者们发现了一个数字序列,它代表着一个未知数组 $A$ 中相邻元素的乘积。

原始数组 $A$ 由 $n$ 个整数 $a_1, a_2, \dots, a_n$ 组成,其中对于 $1 \le i \le n$,满足 $1 \le a_i \le 100$。卷轴上仅存的信息是一个由 $n - 1$ 个整数组成的序列 $b_1, b_2, \dots, b_{n-1}$,它们是 $A$ 中相邻元素乘积的无序集合。换句话说: $$\{b_1, b_2, \dots, b_{n-1}\} = \{a_1 \times a_2, a_2 \times a_3, \dots, a_{n-1} \times a_n\}$$

你的任务是帮助冒险者们重建一个可能的原始数组 $A$。如果存在多个可以得到相同序列 $b$ 的有效数组 $A$,你可以输出其中任意一个。

输入格式

第一行包含一个整数 $n$,表示数组 $A$ 的长度。

第二行包含 $n - 1$ 个空格分隔的整数 $b_1, b_2, \dots, b_{n-1}$,表示数组 $A$ 中相邻元素的乘积。

输出格式

如果不存在这样的数组 $A$,则在一行中输出 No

否则,在第一行输出 Yes。接着,在第二行输出 $n$ 个空格分隔的整数 $a_1, a_2, \dots, a_n$,满足 $\{b_1, b_2, \dots, b_{n-1}\} = \{a_1 \times a_2, a_2 \times a_3, \dots, a_{n-1} \times a_n\}$。

数据范围

  • $1 < n \le 18$
  • 对于 $i \in \{1, 2, \dots, n\}$,满足 $1 \le a_i \le 100$
  • 对于 $i \in \{1, 2, \dots, n - 1\}$,满足 $1 \le b_i \le 10000$

样例

输入样例 1

8
42 32 84 54 48 40 16

输出样例 1

Yes
5 8 4 21 2 8 6 9

输入样例 2

6
45 4 5 4 3

输出样例 2

Yes
3 1 4 1 5 9

输入样例 3

2
3246

输出样例 3

No

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.