A14194 | Baby Ehab Partitions Again
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line contains an integer $n$ ( $2 \le n \le 100$ ) — the length of the array $a$ .
The second line contains $n$ integers $a_1$ , $a_2$ , $\ldots$ , $a_{n}$ ( $1 \le a_i \le 2000$ ) — the elements of the array $a$ .
The second line contains $n$ integers $a_1$ , $a_2$ , $\ldots$ , $a_{n}$ ( $1 \le a_i \le 2000$ ) — the elements of the array $a$ .
输出格式
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.
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.
输入输出样例
输入 #1
4 6 3 9 12
输出 #1
1 2
输入 #2
2 1 2
输出 #2
0
In the first example, you can partition the array into $[6,9]$ and $[3,12]$ , so you must remove at least $1$ element. Removing $3$ is sufficient.
In the second example, the array is already good, so you don't need to remove any elements.
In the second example, the array is already good, so you don't need to remove any elements.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted