CF1779B.MKnez's ConstructiveForces Task

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

MKnez wants to construct an array s1,s2,,sns_1,s_2, \ldots , s_n satisfying the following conditions:

  • Each element is an integer number different from 00 ;
  • For each pair of adjacent elements their sum is equal to the sum of the whole array.

More formally, si0s_i \neq 0 must hold for each 1in1 \leq i \leq n . Moreover, it must hold that s1+s2++sn=si+si+1s_1 + s_2 + \cdots + s_n = s_i + s_{i+1} for each 1i<n1 \leq i < n .

Help MKnez to construct an array with these properties or determine that it does not exist.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t1001 \leq t \leq 100 ). The description of the test cases follows.

The only line of each test case contains a single integer nn ( 2n10002 \leq n \leq 1000 ) — the length of the array.

输出格式

For each test case, print "YES" if an array of length nn satisfying the conditions exists. Otherwise, print "NO". If the answer is "YES", on the next line print a sequence s1,s2,,sns_1,s_2, \ldots, s_n satisfying the conditions. Each element should be a non-zero integer in the range [5000,5000][-5000,5000] , i. e. 5000si5000-5000 \leq s_i \leq 5000 and si0s_i \neq 0 should hold for each 1in1 \leq i \leq n .

It can be proved that if a solution exists then there also exists one which satisfies the additional constraints on the range.

If there are several correct answers, print any of them.

输入输出样例

  • 输入#1

    2
    2
    3

    输出#1

    YES
    9 5
    NO

说明/提示

In the first test case, [9,5][9,5] is a valid answer since 9+59+5 (the sum of the two adjacent elements s1+s2s_1+s_2 ) is equal to 9+59+5 (the sum of all elements). Other solutions include [6,9],[1,2],[5000,5000],[6,-9], [-1,-2], [-5000,5000], \ldots

For the second test case, let us show why some arrays do not satisfy the constraints:

  • [1,1,1][1,1,1]s1+s2=1+1=2s_1+s_2 = 1+1 = 2 and s1+s2+s3=1+1+1=3s_1+s_2+s_3=1+1+1 = 3 differ;
  • [1,1,1][1,-1,1]s1+s2=1+(1)=0s_1+s_2=1+(-1)=0 and s1+s2+s3=1+(1)+1=1s_1+s_2+s_3=1+(-1)+1 = 1 differ;
  • [0,0,0][0,0,0] — The array ss cannot contain a 00 .

This is not a proof, but it can be shown that the answer is "NO".

首页