CF1323A.Even Subset Sum Problem

入门

通过率:0%

时间限制:1.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given an array aa consisting of nn positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by 22) or determine that there is no such subset.

Both the given array and required subset may contain equal values.

给你一个由 nn 个正整数组成的数组 aa。请找出它的一个非空子集,使得该子集中所有元素的和为偶数(即能被 22 整除),或者判断不存在这样的子集。

给定的数组以及所要求的子集均可能包含相等的值。

输入格式

The first line contains a single integer tt (1≤t≤1001 \leq t \leq 100), number of test cases to solve. Descriptions of tt test cases follow.

A description of each test case consists of two lines. The first line contains a single integer nn (1≤n≤1001 \leq n \leq 100), length of array aa.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1001 \leq a_i \leq 100), elements of aa. The given array aa can contain equal values (duplicates).

第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100),表示待解决的测试用例数量。接下来是 tt 个测试用例的描述。

每个测试用例的描述由两行组成。第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100),表示数组 aa 的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1001 \leq a_i \leq 100),即数组 aa 的元素。给定的数组 aa 可能包含相等的值(即存在重复元素)。

输出格式

For each test case output −1-1 if there is no such subset of elements. Otherwise output positive integer kk, number of elements in the required subset. Then output kk distinct integers (1≤pi≤n1 \leq p_i \leq n), indexes of the chosen elements. If there are multiple solutions output any of them.

对于每个测试用例,若不存在满足条件的元素子集,则输出 −1-1;否则输出一个正整数 kk,表示所求子集的元素个数。随后输出 kk 个互不相同的整数(1≤pi≤n1 \leq p_i \leq n),即所选元素的下标。若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#1

    3
    3
    1 4 3
    1
    15
    2
    3 5

    输出#1

    1
    2
    -1
    2
    1 2

说明/提示

There are three test cases in the example.

In the first test case, you can choose the subset consisting of only the second element. Its sum is 44 and it is even.

In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.

In the third test case, the subset consisting of all array's elements has even sum.

示例中包含三个测试用例。

在第一个测试用例中,你可以选择仅包含第二个元素的子集。其和为 44,是偶数。

在第二个测试用例中,唯一一个非空子集仅包含第一个元素,但其和为奇数,因此无解。

在第三个测试用例中,由数组所有元素构成的子集的和为偶数。

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

首页