CF1407A.Ahahahahahahahaha

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Alexandra has an even-length array aa, consisting of 00s and 11s. The elements of the array are enumerated from 11 to nn. She wants to remove at most n2\frac{n}{2} elements (where nn — length of array) in the way that alternating sum of the array will be equal 00 (i.e. a1−a2+a3−a4+…=0a_1 - a_2 + a_3 - a_4 + \dotsc = 0). In other words, Alexandra wants sum of all elements at the odd positions and sum of all elements at the even positions to become equal. The elements that you remove don't have to be consecutive.

For example, if she has a=[1,0,1,0,0,0]a = [1, 0, 1, 0, 0, 0] and she removes 22nd and 44th elements, aa will become equal [1,1,0,0][1, 1, 0, 0] and its alternating sum is 1−1+0−0=01 - 1 + 0 - 0 = 0.

Help her!

亚历山德拉有一个长度为偶数的数组 aa,其中只包含 00 和 11。数组元素从 11 编号至 nn。她希望最多删除 n2\frac{n}{2} 个元素(其中 nn 为数组长度),使得剩余数组的交错和(alternating sum)等于 00(即 a1−a2+a3−a4+…=0a_1 - a_2 + a_3 - a_4 + \dotsc = 0)。换言之,亚历山德拉希望剩余数组中所有奇数位置上的元素之和,与所有偶数位置上的元素之和相等。被删除的元素不必连续。

例如,若她拥有数组 a=[1,0,1,0,0,0]a = [1, 0, 1, 0, 0, 0],并删除第 22 个和第 44 个元素,则 aa 变为 [1,1,0,0][1, 1, 0, 0],其交错和为 1−1+0−0=01 - 1 + 0 - 0 = 0。

请帮助她!

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1031 \le t \le 10^3). Description of the test cases follows.

The first line of each test case contains a single integer nn (2≤n≤1032 \le n \le 10^3, nn is even) — length of the array.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤10 \le a_i \le 1) — elements of the array.

It is guaranteed that the sum of nn over all test cases does not exceed 10310^3.

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

每个测试用例的第一行包含一个整数 nn(2≤n≤1032 \le n \le 10^3,且 nn 为偶数)—— 数组的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤10 \le a_i \le 1)—— 数组的元素。

保证所有测试用例的 nn 之和不超过 10310^3。

输出格式

For each test case, firstly, print kk (n2≤k≤n\frac{n}{2} \leq k \leq n) — number of elements that will remain after removing in the order they appear in aa. Then, print this kk numbers. Note that you should print the numbers themselves, not their indices.

We can show that an answer always exists. If there are several answers, you can output any of them.

对于每个测试用例,首先输出 kk(其中 n2≤k≤n\frac{n}{2} \leq k \leq n)—— 即按数组 aa 中原有顺序保留下来的元素个数。然后,输出这 kk 个数。注意:您应输出这些数本身,而非它们的下标。

可以证明答案一定存在。若存在多个合法答案,您可以输出其中任意一个。

输入输出样例

  • 输入#1

    4
    2
    1 0
    2
    0 0
    4
    0 1 1 1
    4
    1 1 0 0

    输出#1

    1
    0
    1
    0
    2
    1 1
    4
    1 1 0 0

说明/提示

In the first and second cases, alternating sum of the array, obviously, equals 00.

In the third case, alternating sum of the array equals 1−1=01 - 1 = 0.

In the fourth case, alternating sum already equals 1−1+0−0=01 - 1 + 0 - 0 = 0, so we don't have to remove anything.

在第一和第二种情况下,数组的交错和显然等于 00。

在第三种情况下,数组的交错和等于 1−1=01 - 1 = 0。

在第四种情况下,交错和已经等于 1−1+0−0=01 - 1 + 0 - 0 = 0,因此无需删除任何元素。

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

首页