A15927 | A-characteristic
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Consider an array $a_1, a_2, \dots, a_n$ consisting of numbers $1$ and $-1$ . Define $A$ -characteristic of this array as a number of pairs of indices $1 \le i < j \le n$ , such that $a_i \cdot a_j = 1$ .
Find any array $a$ with given length $n$ with $A$ -characteristic equal to the given value $k$ .
Find any array $a$ with given length $n$ with $A$ -characteristic equal to the given value $k$ .
输入格式
Each test contains multiple test cases. The first line contains the number of test cases $t$ ( $1 \le t \le 100$ ). The description of the test cases follows.
The only line of each test case contains two integers $n$ and $k$ ( $2 \le n \le 100$ ; $0 \le k \le \frac{(n-1) n}{2}$ ) — the length of required array and required $A$ -characteristic.
The only line of each test case contains two integers $n$ and $k$ ( $2 \le n \le 100$ ; $0 \le k \le \frac{(n-1) n}{2}$ ) — the length of required array and required $A$ -characteristic.
输出格式
For each test case, if there is no array $a$ with given $A$ -characteristic $k$ , print NO.
Otherwise, print YES and $n$ numbers $1$ and $-1$ , which form the required array $a$ . If there are multiple answers, print any of them.
Otherwise, print YES and $n$ numbers $1$ and $-1$ , which form the required array $a$ . If there are multiple answers, print any of them.
输入输出样例
输入 #1
7 2 0 2 1 3 1 3 2 3 3 5 4 5 5
输出 #1
YES 1 -1 YES 1 1 YES 1 -1 1 NO YES 1 1 1 YES -1 1 -1 1 1 NO
In the first test case, there is only one pair of different elements in the array, and their product is $a_1 \cdot a_2 = -1 \neq 1$ , hence its $A$ -characteristic is $0$ .
In the second test case, there is only one pair of different elements in the array, and their product is $a_1 \cdot a_2 = 1$ , hence its $A$ -characteristic is $1$ .
In the third test case, there are three pairs of different elements in the array, and their product are: $a_1 \cdot a_2 = -1$ , $a_1 \cdot a_3 = 1$ , $a_2 \cdot a_3 = -1$ , hence its $A$ -characteristic is $1$ .
In the fourth test case, we can show, that there is no array with length $3$ , which $A$ -characteristic is $2$ .
In the second test case, there is only one pair of different elements in the array, and their product is $a_1 \cdot a_2 = 1$ , hence its $A$ -characteristic is $1$ .
In the third test case, there are three pairs of different elements in the array, and their product are: $a_1 \cdot a_2 = -1$ , $a_1 \cdot a_3 = 1$ , $a_2 \cdot a_3 = -1$ , hence its $A$ -characteristic is $1$ .
In the fourth test case, we can show, that there is no array with length $3$ , which $A$ -characteristic is $2$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted