310369: CF1823A. A-characteristic

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

A. A-characteristictime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

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$.

Input

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.

Output

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.

ExampleInput
7
2 0
2 1
3 1
3 2
3 3
5 4
5 5
Output
YES
1 -1 
YES
1 1 
YES
1 -1 1 
NO
YES
1 1 1 
YES
-1 1 -1 1 1 
NO
Note

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$.

Input

题意翻译

构建一个长度为 $n$ 的数组,数组元素只能为 $1$ 或者 $-1$。 定义数组每满足一对 $a_{i} \cdot a_{j} = 1$ $( 1 \leq i < j \leq n )$ 为有 $1$ 个特征 $A$。求数组是否能构成出满足刚好 $k$ 个特征 $A$。如果能构成该数组输出 YES 并给出构造数组。反之只输出 NO。

Output

题目大意:给定一个由1和-1组成的数组a,定义A特性为满足a_i * a_j = 1的索引对(i, j)的数量。给定数组长度n和A特性值k,构造一个满足条件的数组a。

输入数据格式:第一行包含一个整数t(1 ≤ t ≤ 100),表示测试用例的数量。接下来t行,每行包含两个整数n和k(2 ≤ n ≤ 100; 0 ≤ k ≤ (n-1)n/2),分别表示数组的长度和A特性值。

输出数据格式:对于每个测试用例,如果不存在满足条件的数组a,输出"NO"。否则,输出"YES"和一个由n个1和-1组成的数组a。如果有多个答案,输出其中任意一个。题目大意:给定一个由1和-1组成的数组a,定义A特性为满足a_i * a_j = 1的索引对(i, j)的数量。给定数组长度n和A特性值k,构造一个满足条件的数组a。 输入数据格式:第一行包含一个整数t(1 ≤ t ≤ 100),表示测试用例的数量。接下来t行,每行包含两个整数n和k(2 ≤ n ≤ 100; 0 ≤ k ≤ (n-1)n/2),分别表示数组的长度和A特性值。 输出数据格式:对于每个测试用例,如果不存在满足条件的数组a,输出"NO"。否则,输出"YES"和一个由n个1和-1组成的数组a。如果有多个答案,输出其中任意一个。

加入题单

上一题 下一题 算法标签: