#P15913. [TOPC 2024] In Search of the Lost Array

    ID: 15836 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP2024ICPC台湾状压 DP

[TOPC 2024] In Search of the Lost Array

Description

In a forgotten realm, a group of adventurers stumbles upon a set of mysterious scrolls hidden deep within an ancient library. These scrolls hold the secrets of a powerful numerical array that controls the magic of the realm. However, the scrolls have been damaged over time, and only fragments remain. Specifically, the adventurers discover a sequence of numbers representing the products of adjacent elements of an unknown array AA.

The original array AA consists of nn integers a1,a2,,ana_1, a_2, \dots, a_n where 1ai1001 \le a_i \le 100 for 1in1 \le i \le n. The only information remaining on the scrolls is a sequence of n1n-1 integers b1,b2,,bn1b_1, b_2, \dots, b_{n-1}, which are unordered products of adjacent elements from AA. In other words:

$$\{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\}$$

Your task is to help the adventurers reconstruct one possible original array AA. If there are multiple valid arrays AA that could result in the same sequence bb, you may output any of them.

Input Format

The first line contains a single integer nn, representing the length of the array AA. The second line contains n1n-1 space-separated integers b1,b2,,bn1b_1, b_2, \dots, b_{n-1}, representing the products of adjacent elements in the array AA.

Output Format

If there is no such array AA, then print No on a line. Otherwise, print Yes on the first line. Then, output nn space-separated integers a1,a2,,ana_1, a_2, \dots, a_n on the second line, where $\{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\}$.

8
42 32 84 54 48 40 16
Yes
5 8 4 21 2 8 6 9
6
45 4 5 4 3
Yes
3 1 4 1 5 9
2
3246
No

Hint

  • 1<n181 < n \le 18.
  • 1ai1001 \le a_i \le 100 for i{1,2,,n}i \in \{1, 2, \dots, n\}
  • 1bi100001 \le b_i \le 10000 for i{1,2,,n1}i \in \{1, 2, \dots, n - 1\}