CF1536A.Omkar and Bad Story

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Omkar has received a message from Anton saying "Your story for problem A is confusing. Just make a formal statement." Because of this, Omkar gives you an array a=[a1,a2,…,an]a = [a_1, a_2, \ldots, a_n] of nn distinct integers. An array b=[b1,b2,…,bk]b = [b_1, b_2, \ldots, b_k] is called nice if for any two distinct elements bi,bjb_i, b_j of bb, ∣bi−bj∣|b_i-b_j| appears in bb at least once. In addition, all elements in bb must be distinct. Can you add several (maybe, 00) integers to aa to create a nice array bb of size at most 300300? If aa is already nice, you don't have to add any elements.

For example, array [3,6,9][3, 6, 9] is nice, as ∣6−3∣=∣9−6∣=3|6-3|=|9-6| = 3, which appears in the array, and ∣9−3∣=6|9-3| = 6, which appears in the array, while array [4,2,0,6,9][4, 2, 0, 6, 9] is not nice, as ∣9−4∣=5|9-4| = 5 is not present in the array.

For integers xx and yy, ∣x−y∣=x−y|x-y| = x-y if x>yx \gt y and ∣x−y∣=y−x|x-y| = y-x otherwise.

奥姆卡尔收到了安东发来的一条消息:“问题 A 的题面故事令人困惑,直接给出形式化的题意即可。”因此,奥姆卡尔给你一个由 nn 个互不相同的整数组成的数组 a=[a1,a2,…,an]a = [a_1, a_2, \ldots, a_n]。称一个数组 b=[b1,b2,…,bk]b = [b_1, b_2, \ldots, b_k] 是优美的(nice),当且仅当对 bb 中任意两个不同元素 bi,bjb_i, b_j,其绝对差值 ∣bi−bj∣|b_i-b_j| 至少在 bb 中出现一次;此外,bb 中所有元素必须互不相同。你能否向 aa 中添加若干(可能为 00 个)整数,构造出一个大小不超过 300300 的优美数组 bb?如果 aa 本身已是优美的,则无需添加任何元素。

例如,数组 [3,6,9][3, 6, 9] 是优美的,因为 ∣6−3∣=∣9−6∣=3|6-3|=|9-6| = 3 出现在该数组中,且 ∣9−3∣=6|9-3| = 6 也出现在该数组中;而数组 [4,2,0,6,9][4, 2, 0, 6, 9] 不是优美的,因为 ∣9−4∣=5|9-4| = 5 并未出现在该数组中。

对于整数 xx 和 yy,定义 ∣x−y∣=x−y|x-y| = x-y(若 x>yx > y),否则 ∣x−y∣=y−x|x-y| = y-x。

输入格式

Each test contains multiple test cases. The first line contains tt (1≤t≤501 \leq t \leq 50), the number of test cases. Description of the test cases follows.

The first line of each test case contains a single integer nn (2≤n≤1002 \leq n \leq 100) — the length of the array aa.

The second line of each test case contains nn distinct integers a1,a2,⋯ ,ana_1, a_2, \cdots, a_n (−100≤ai≤100-100 \leq a_i \leq 100) — the elements of the array aa.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤501 \leq t \leq 50),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤1002 \leq n \leq 100)—— 表示数组 aa 的长度。

每个测试用例的第二行包含 nn 个互不相同的整数 a1,a2,⋯ ,ana_1, a_2, \cdots, a_n(−100≤ai≤100-100 \leq a_i \leq 100)—— 表示数组 aa 的元素。

输出格式

For each test case, output one line containing YES if Omkar can create a nice array bb by adding elements to aa and NO otherwise. The case of each letter does not matter, so yEs and nO will also be accepted.

If the first line is YES, output a second line containing a single integer kk (n≤k≤300n \leq k \leq 300).

Then output one line containing kk distinct integers b1,b2,⋯ ,bkb_1, b_2, \cdots, b_k (−109≤bi≤109-10^9 \leq b_i \leq 10^9), the elements of the nice array bb. b1,b2,⋯ ,bkb_1, b_2, \cdots, b_k can be in any order. For each aia_i in aa, aia_i must appear at least once in bb.

It can be proved that if Omkar can create such an array bb, then he can also do so in a way that satisfies the above constraints.

If multiple solutions exist, you can print any.

对于每个测试用例,如果 Omkar 能够通过向数组 aa 中添加元素来构造一个“好”数组 bb,则输出一行 YES;否则输出 NO。字母大小写不敏感,因此 yEs 和 nO 同样被接受。

若首行为 YES,则需在第二行输出一个整数 kk(满足 n≤k≤300n \leq k \leq 300)。

接着输出一行,包含 kk 个互不相同的整数 b1,b2,⋯ ,bkb_1, b_2, \cdots, b_k(满足 −109≤bi≤109-10^9 \leq b_i \leq 10^9),即“好”数组 bb 的元素。b1,b2,⋯ ,bkb_1, b_2, \cdots, b_k 的顺序可任意。对 aa 中的每个 aia_i,它必须至少在 bb 中出现一次。

可以证明:若 Omkar 能构造出这样的数组 bb,则他一定也能以满足上述约束的方式构造出来。

若存在多个可行解,输出任意一个即可。

输入输出样例

  • 输入#1

    4
    3
    3 0 9
    2
    3 4
    5
    -7 3 13 -2 8
    4
    4 8 12 6

    输出#1

    yes
    4
    6 0 3 9
    yEs
    5
    5 3 1 2 4
    NO
    Yes
    6
    8 12 6 2 4 10

说明/提示

For the first case, you can add integers to aa to receive the array b=[6,0,3,9]b = [6, 0, 3, 9]. Note that ∣6−3∣=∣9−6∣=∣3−0∣=3|6-3| = |9-6| = |3-0| = 3 and 33 is in bb, ∣6−0∣=∣9−3∣=6|6-0| = |9-3| = 6 and 66 is in bb, and ∣9−0∣=9|9-0| = 9 is in bb, so bb is nice.

For the second case, you can add integers to aa to receive the array b=[5,3,1,2,4]b = [5, 3, 1, 2, 4]. We have that ∣2−1∣=∣3−2∣=∣4−3∣=∣5−4∣=1|2-1| = |3-2| = |4-3| = |5-4| = 1 is in bb, ∣3−1∣=∣4−2∣=∣5−3∣=2|3-1| = |4-2| = |5-3| = 2 is in bb, ∣4−1∣=∣5−2∣=3|4-1| = |5-2| = 3 is in bb, and ∣5−1∣=4|5-1| = 4 is in bb, so bb is nice.

For the fourth case, you can add integers to aa to receive the array b=[8,12,6,2,4,10]b = [8, 12, 6, 2, 4, 10]. We have that ∣4−2∣=∣6−4∣=∣8−6∣=∣10−8∣=∣12−10∣=2|4-2| = |6-4| = |8-6| = |10-8| = |12-10| = 2 is in bb, ∣6−2∣=∣8−4∣=∣10−6∣=∣12−8∣=4|6-2| = |8-4| = |10-6| = |12-8| = 4 is in bb, ∣8−2∣=∣10−4∣=∣12−6∣=6|8-2| = |10-4| = |12-6| = 6 is in bb, ∣10−2∣=∣12−4∣=8|10-2| = |12-4| = 8 is in bb, and ∣12−2∣=10|12-2| = 10 is in bb, so bb is nice.

It can be proven that for all other test cases it is impossible to create a nice array bb.

对于第一种情况,你可以向数组 aa 中添加整数,得到数组 b=[6,0,3,9]b = [6, 0, 3, 9]。注意 ∣6−3∣=∣9−6∣=∣3−0∣=3|6-3| = |9-6| = |3-0| = 3,且 3∈b3 \in b;∣6−0∣=∣9−3∣=6|6-0| = |9-3| = 6,且 6∈b6 \in b;∣9−0∣=9|9-0| = 9,且 9∈b9 \in b,因此 bb 是“优美的”。

对于第二种情况,你可以向数组 aa 中添加整数,得到数组 b=[5,3,1,2,4]b = [5, 3, 1, 2, 4]。我们有 ∣2−1∣=∣3−2∣=∣4−3∣=∣5−4∣=1|2-1| = |3-2| = |4-3| = |5-4| = 1,且 1∈b1 \in b;∣3−1∣=∣4−2∣=∣5−3∣=2|3-1| = |4-2| = |5-3| = 2,且 2∈b2 \in b;∣4−1∣=∣5−2∣=3|4-1| = |5-2| = 3,且 3∈b3 \in b;∣5−1∣=4|5-1| = 4,且 4∈b4 \in b,因此 bb 是“优美的”。

对于第四种情况,你可以向数组 aa 中添加整数,得到数组 b=[8,12,6,2,4,10]b = [8, 12, 6, 2, 4, 10]。我们有 ∣4−2∣=∣6−4∣=∣8−6∣=∣10−8∣=∣12−10∣=2|4-2| = |6-4| = |8-6| = |10-8| = |12-10| = 2,且 2∈b2 \in b;∣6−2∣=∣8−4∣=∣10−6∣=∣12−8∣=4|6-2| = |8-4| = |10-6| = |12-8| = 4,且 4∈b4 \in b;∣8−2∣=∣10−4∣=∣12−6∣=6|8-2| = |10-4| = |12-6| = 6,且 6∈b6 \in b;∣10−2∣=∣12−4∣=8|10-2| = |12-4| = 8,且 8∈b8 \in b;∣12−2∣=10|12-2| = 10,且 10∈b10 \in b,因此 bb 是“优美的”。

可以证明:对于其余所有测试用例,均无法构造出“优美”的数组 bb。

输入解题思路,AI测评打分。不知道怎么写?

首页