CF1417B.Two Arrays
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
RedDreamer has an array a consisting of n non-negative integers, and an unlucky integer T.
Let's denote the misfortune of array b having length m as f(b) — the number of pairs of integers (i,j) such that 1≤i<j≤m and bi+bj=T. RedDreamer has to paint each element of a into one of two colors, white and black (for each element, the color is chosen independently), and then create two arrays c and d so that all white elements belong to c, and all black elements belong to d (it is possible that one of these two arrays becomes empty). RedDreamer wants to paint the elements in such a way that f(c)+f(d) is minimum possible.
For example:
- if n=6, T=7 and a=[1,2,3,4,5,6], it is possible to paint the 1-st, the 4-th and the 5-th elements white, and all other elements black. So c=[1,4,5], d=[2,3,6], and f(c)+f(d)=0+0=0;
- if n=3, T=6 and a=[3,3,3], it is possible to paint the 1-st element white, and all other elements black. So c=[3], d=[3,3], and f(c)+f(d)=0+1=1.
Help RedDreamer to paint the array optimally!
RedDreamer 有一个由 n 个非负整数组成的数组 a,以及一个不幸运的整数 T。
我们用 f(b) 表示长度为 m 的数组 b 的“不幸值”——即满足 1≤i<j≤m 且 bi+bj=T 的整数对 (i,j) 的数量。RedDreamer 需要将数组 a 中的每个元素独立地涂成两种颜色之一:白色或黑色;然后构造两个数组 c 和 d,使得所有白色元素构成 c,所有黑色元素构成 d(允许 c 或 d 为空)。RedDreamer 希望以某种方式给元素上色,使得 f(c)+f(d) 达到最小可能值。
例如:
- 若 n=6,T=7,且 a=[1,2,3,4,5,6],可将第 1、第 4 和第 5 个元素涂成白色,其余涂成黑色。于是 c=[1,4,5],d=[2,3,6],且 f(c)+f(d)=0+0=0;
- 若 n=3,T=6,且 a=[3,3,3],可将第 1 个元素涂成白色,其余涂成黑色。于是 c=[3],d=[3,3],且 f(c)+f(d)=0+1=1。
请帮助 RedDreamer 实现最优涂色!
输入格式
The first line contains one integer t (1≤t≤1000) — the number of test cases. Then t test cases follow.
The first line of each test case contains two integers n and T (1≤n≤105, 0≤T≤109) — the number of elements in the array and the unlucky integer, respectively.
The second line contains n integers a1, a2, ..., an (0≤ai≤109) — the elements of the array.
The sum of n over all test cases does not exceed 105.
第一行包含一个整数 t(1≤t≤1000)—— 测试用例的数量。接下来是 t 个测试用例。
每个测试用例的第一行包含两个整数 n 和 T(1≤n≤105,0≤T≤109)—— 分别表示数组的元素个数和“不幸运”整数。
每个测试用例的第二行包含 n 个整数 a1, a2, ..., an(0≤ai≤109)—— 数组的元素。
所有测试用例中 n 的总和不超过 105。
输出格式
For each test case print n integers: p1, p2, ..., pn (each pi is either 0 or 1) denoting the colors. If pi is 0, then ai is white and belongs to the array c, otherwise it is black and belongs to the array d.
If there are multiple answers that minimize the value of f(c)+f(d), print any of them.
对于每个测试用例,输出 n 个整数:p1、p2、…、pn(每个 pi 为 0 或 1),表示颜色。若 pi=0,则 ai 为白色,属于数组 c;否则 ai 为黑色,属于数组 d。
若存在多个使 f(c)+f(d) 的值最小的解,输出其中任意一个即可。
输入输出样例
输入#1
2 6 7 1 2 3 4 5 6 3 6 3 3 3
输出#1
1 0 0 1 1 0 1 0 0
输入解题思路,AI测评打分。不知道怎么写?