A16393 | Permutation of Given
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
输入格式
Each test case contains only one number, $n$ ( $2 \leq n \leq 10^6$ ).
输出格式
If a solution exists, output "YES" (without quotes), followed by an array $a$ ( $-10^9 \leq a_i \leq 10^9, a_i \neq 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.
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.
输入输出样例
输入 #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.
In the second test, it can be shown that there is no solution.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted