CF1918G.Permutation of Given
省选/NOI-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You were given only one number, n. It didn't seem interesting to you, so you wondered if it's possible to come up with an array of length n consisting of non-zero integers, such that if each element of the array is replaced by the sum of its neighbors (the elements on the ends are replaced by their only neighbors), you obtain a permutation of the numbers in the original array.
你仅得到了一个数字 n。它看起来并不有趣,因此你开始思考:能否构造一个长度为 n 的、由非零整数组成的数组,使得将该数组中每个元素替换为其相邻元素之和(两端的元素仅有一个相邻元素,故以其唯一相邻元素替代)后,所得数组恰好是原数组中数字的一个排列?
输入格式
Each test case contains only one number, n (2≤n≤106).
每个测试用例仅包含一个数字 n(2≤n≤106)。
输出格式
If a solution exists, output "YES" (without quotes), followed by an array a (−109≤ai≤109,ai=0) that satisfies the condition of the problem. If there are multiple possible answers, output any of them.
If there is no suitable array, output "NO" (without quotes).
The words "YES" and "NO" can be output in any case, for example, "YES", "Yes", "yEs", and so on.
如果存在解,输出“YES”(不带引号),然后输出一个数组 a(满足 −109≤ai≤109 且 ai=0),使其满足题目的条件。若存在多个可能的答案,输出任意一个即可。
如果不存在满足条件的数组,则输出“NO”(不带引号)。
“YES”和“NO”可以以任意大小写形式输出,例如“YES”、“Yes”、“yEs”等。
输入输出样例
输入#1
4
输出#1
YES 1 2 -2 -1
输入#2
5
输出#2
NO
说明/提示
In the first test, the array [1,2,−2,−1] is suitable, because if each element is replaced by the sum of its neighbors, the resulting array is [2,−1,1,−2], which is a permutation of the original array.
In the second test, it can be shown that there is no solution.
在第一个测试用例中,数组 [1,2,−2,−1] 是可行的,因为若将每个元素替换为其相邻元素之和,则得到的新数组为 [2,−1,1,−2],该数组是原数组的一个排列。
在第二个测试用例中,可以证明不存在满足条件的解。
输入解题思路,AI测评打分。不知道怎么写?