CF1779B.MKnez's ConstructiveForces Task
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
MKnez wants to construct an array s1,s2,…,sn satisfying the following conditions:
- Each element is an integer number different from 0;
- For each pair of adjacent elements their sum is equal to the sum of the whole array.
More formally, si=0 must hold for each 1≤i≤n. Moreover, it must hold that s1+s2+⋯+sn=si+si+1 for each 1≤i<n.
Help MKnez to construct an array with these properties or determine that it does not exist.
MKnez 想要构造一个数组 s1,s2,…,sn,满足以下条件:
- 每个元素均为非零整数;
- 每一对相邻元素之和等于整个数组所有元素的总和。
更形式化地说,对每个 1≤i≤n,必须满足 si=0;此外,对每个 1≤i<n,必须满足 s1+s2+⋯+sn=si+si+1。
请帮助 MKnez 构造出满足这些性质的数组,或判断这样的数组不存在。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤100). The description of the test cases follows.
The only line of each test case contains a single integer n (2≤n≤1000) — the length of the array.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤100)。随后是测试用例的描述。
每个测试用例仅有一行,包含一个整数 n(2≤n≤1000)—— 数组的长度。
输出格式
For each test case, print "YES" if an array of length n satisfying the conditions exists. Otherwise, print "NO". If the answer is "YES", on the next line print a sequence s1,s2,…,sn satisfying the conditions. Each element should be a non-zero integer in the range [−5000,5000], i. e. −5000≤si≤5000 and si=0 should hold for each 1≤i≤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.
对于每个测试用例,如果存在长度为 n 且满足条件的数组,则输出 "YES";否则输出 "NO"。若答案为 "YES",则在下一行输出一个满足条件的序列 s1,s2,…,sn。序列中每个元素都必须是非零整数,且取值范围为 [−5000,5000],即对每个 1≤i≤n,需满足 −5000≤si≤5000 且 si=0。
可以证明:若解存在,则必存在一个解满足上述范围限制。
若存在多个正确答案,输出任意一个即可。
输入输出样例
输入#1
2 2 3
输出#1
YES 9 5 NO
说明/提示
In the first test case, [9,5] is a valid answer since 9+5 (the sum of the two adjacent elements s1+s2) is equal to 9+5 (the sum of all elements). Other solutions include [6,−9],[−1,−2],[−5000,5000],…
For the second test case, let us show why some arrays do not satisfy the constraints:
- [1,1,1] — s1+s2=1+1=2 and s1+s2+s3=1+1+1=3 differ;
- [1,−1,1] — s1+s2=1+(−1)=0 and s1+s2+s3=1+(−1)+1=1 differ;
- [0,0,0] — The array s cannot contain a 0.
This is not a proof, but it can be shown that the answer is "NO".
在第一个测试用例中,[9,5] 是一个合法的答案,因为 9+5(两个相邻元素 s1+s2 的和)等于 9+5(所有元素的总和)。其他合法解还包括 [6,−9],[−1,−2],[−5000,5000],…
在第二个测试用例中,我们说明为何某些数组不满足约束条件:
- [1,1,1] — s1+s2=1+1=2,而 s1+s2+s3=1+1+1=3,二者不相等;
- [1,−1,1] — s1+s2=1+(−1)=0,而 s1+s2+s3=1+(−1)+1=1,二者不相等;
- [0,0,0] — 数组 s 中不能包含 0。
这并非严格证明,但可以证明该测试用例的答案为 “NO”。
输入解题思路,AI测评打分。不知道怎么写?