Codeforces Round #717 (Div. 2) C. Baby Ehab Partitions Again(思维)

Baby Ehab was toying around with arrays. He has an array a of length n. He defines an array to be good if there's no way to partition it into 2 subsequences such that the sum of the elements in the first is equal to the sum of the elements in the second. Now he wants to remove the minimum number of elements in 𝑎a so that it becomes a good array. Can you help him?

A sequence b is a subsequence of an array 𝑎a if 𝑏b can be obtained from a by deleting some (possibly zero or all) elements. A partitioning of an array is a way to divide it into 2 subsequences such that every element belongs to exactly one subsequence, so you must use all the elements, and you can't share any elements.

Input

The first line contains an integer n (2≤n≤100) — the length of the array 𝑎a.

The second line contains 𝑛n integers a1, a2, ……, an (1≤ai≤2000) — the elements of the array a.

Output

The first line should contain the minimum number of elements you need to remove.

The second line should contain the indices of the elements you're removing, separated by spaces.

We can show that an answer always exists. If there are multiple solutions, you can print any.

Examples

input

Copy

4
6 3 9 12

output

Copy

1
2

input

Copy

2
1 2

output

Copy

0

首先判断是否已经是好的序列,直接背包dp判断即可(当然如果和为奇数直接输出0)。然后只要序列中有一个奇数,就删掉这个数即可,因为删掉以后sum就为奇数了。其次如果序列全是偶数,则将每个数除以所有数的GCD,得到的序列必然含有奇数,再从里面找奇数删除即可。原理就是两个相等的子序列同乘一个数还是相等的。

#include <bits/stdc++.h>
using namespace std;
int n;
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}
bool dp[105][200005];
int a[105], b[2005];
int main() {
	cin >> n;
	int sum = 0;
	memset(b, 0, sizeof(b));
	memset(dp, 0, sizeof(dp));
	int GCD = a[1];
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		sum += a[i];
		b[a[i]]++;
		GCD = gcd(GCD, a[i]);
	}
	for(int i = 1; i <= n; i++) {
		dp[i][a[i]] = 1;//必须先排序再初始化
		dp[i][0] = 1;
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j <= 200000; j++) {
			if(j - a[i] >= 0) dp[i][j] |= dp[i - 1][j - a[i]];
			dp[i][j] |= dp[i - 1][j];//不要忘记当前不选的情况
		}
	}
	if(sum & 1 || !dp[n][sum / 2]) {
		cout << 0;
		return 0;
	}
	cout << 1 << endl;
	for(int i = 1; i <= n; i++) {
		if(a[i] & 1) {
			cout << i;
			return 0;
		}
	}
	for(int i = 1; i <= n; i++) a[i] /= GCD;
	for(int i = 1; i <= n; i++) {
		if(a[i] & 1) {
			cout << i;
			return 0;
		}
	}
	return 0;
}
//2 3 5 10
//2 4 4 10 12

posted @   脂环  阅读(123)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示
主题色彩