CF1823A.A-characteristic

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Consider an array a1,a2,…,ana_1, a_2, \dots, a_n consisting of numbers 11 and −1-1. Define AA-characteristic of this array as a number of pairs of indices 1≤i<j≤n1 \le i \lt j \le n, such that ai⋅aj=1a_i \cdot a_j = 1.

Find any array aa with given length nn with AA-characteristic equal to the given value kk.

考虑一个由数字 11 和 −1-1 组成的数组 a1,a2,…,ana_1, a_2, \dots, a_n。定义该数组的 AA-特征值为满足 1≤i<j≤n1 \le i \lt j \le n 且 ai⋅aj=1a_i \cdot a_j = 1 的下标对 (i,j)(i, j) 的个数。

请构造任意一个长度为 nn 的数组 aa,使其 AA-特征值恰好等于给定值 kk。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). The description of the test cases follows.

The only line of each test case contains two integers nn and kk (2≤n≤1002 \le n \le 100; 0≤k≤(n−1)n20 \le k \le \frac{(n-1) n}{2}) — the length of required array and required AA-characteristic.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1001 \le t \le 100)。随后是测试用例的描述。

每个测试用例仅有一行,包含两个整数 nn 和 kk(2≤n≤1002 \le n \le 100;0≤k≤(n−1)n20 \le k \le \frac{(n-1) n}{2})——分别为所求数组的长度和所需的 AA-特征值。

输出格式

For each test case, if there is no array aa with given AA-characteristic kk, print NO.

Otherwise, print YES and nn numbers 11 and −1-1, which form the required array aa. If there are multiple answers, print any of them.

对于每个测试用例,若不存在满足给定 AA-特征值 kk 的数组 aa,则输出 NO。

否则,输出 YES,以及 nn 个数(每个数为 11 或 −1-1),它们构成所要求的数组 aa。若存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#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 a1⋅a2=−1≠1a_1 \cdot a_2 = -1 \neq 1, hence its AA-characteristic is 00.

In the second test case, there is only one pair of different elements in the array, and their product is a1⋅a2=1a_1 \cdot a_2 = 1, hence its AA-characteristic is 11.

In the third test case, there are three pairs of different elements in the array, and their product are: a1⋅a2=−1a_1 \cdot a_2 = -1, a1⋅a3=1a_1 \cdot a_3 = 1, a2⋅a3=−1a_2 \cdot a_3 = -1, hence its AA-characteristic is 11.

In the fourth test case, we can show, that there is no array with length 33, which AA-characteristic is 22.

在第一个测试用例中,数组中只有一对不同的元素,它们的乘积为 a1⋅a2=−1≠1a_1 \cdot a_2 = -1 \neq 1,因此其 AA-特征值为 00。

在第二个测试用例中,数组中只有一对不同的元素,它们的乘积为 a1⋅a2=1a_1 \cdot a_2 = 1,因此其 AA-特征值为 11。

在第三个测试用例中,数组中有三对不同的元素,它们的乘积分别为:a1⋅a2=−1a_1 \cdot a_2 = -1,a1⋅a3=1a_1 \cdot a_3 = 1,a2⋅a3=−1a_2 \cdot a_3 = -1,因此其 AA-特征值为 11。

在第四个测试用例中,我们可以证明:不存在长度为 33 且 AA-特征值为 22 的数组。

输入解题思路,AI测评打分。不知道怎么写?

首页