A9103 | Vasily the Bear and Sequence
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vasily the bear has got a sequence of positive integers $a_{1},a_{2},...,a_{n}$ . Vasily the Bear wants to write out several numbers on a piece of paper so that the beauty of the numbers he wrote out was maximum.
The beauty of the written out numbers $b_{1},b_{2},...,b_{k}$ is such maximum non-negative integer $v$ , that number $b_{1}$ $and$ $b_{2}$ $and$ $...$ $and$ $b_{k}$ is divisible by number $2^{v}$ without a remainder. If such number $v$ doesn't exist (that is, for any non-negative integer $v$ , number $b_{1}$ $and$ $b_{2}$ $and$ $...$ $and$ $b_{k}$ is divisible by $2^{v}$ without a remainder), the beauty of the written out numbers equals -1.
Tell the bear which numbers he should write out so that the beauty of the written out numbers is maximum. If there are multiple ways to write out the numbers, you need to choose the one where the bear writes out as many numbers as possible.
Here expression $x$ $and$ $y$ means applying the bitwise AND operation to numbers $x$ and $y$ . In programming languages C++ and Java this operation is represented by "&", in Pascal — by "and".
The beauty of the written out numbers $b_{1},b_{2},...,b_{k}$ is such maximum non-negative integer $v$ , that number $b_{1}$ $and$ $b_{2}$ $and$ $...$ $and$ $b_{k}$ is divisible by number $2^{v}$ without a remainder. If such number $v$ doesn't exist (that is, for any non-negative integer $v$ , number $b_{1}$ $and$ $b_{2}$ $and$ $...$ $and$ $b_{k}$ is divisible by $2^{v}$ without a remainder), the beauty of the written out numbers equals -1.
Tell the bear which numbers he should write out so that the beauty of the written out numbers is maximum. If there are multiple ways to write out the numbers, you need to choose the one where the bear writes out as many numbers as possible.
Here expression $x$ $and$ $y$ means applying the bitwise AND operation to numbers $x$ and $y$ . In programming languages C++ and Java this operation is represented by "&", in Pascal — by "and".
输入格式
The first line contains integer $n$ ( $1<=n<=10^{5}$ ). The second line contains $n$ space-separated integers $a_{1},a_{2},...,a_{n}$ $(1<=a_{1}<a_{2}<...<a_{n}<=10^{9})$ .
输出格式
In the first line print a single integer $k$ $(k>0)$ , showing how many numbers to write out. In the second line print $k$ integers $b_{1},b_{2},...,b_{k}$ — the numbers to write out. You are allowed to print numbers $b_{1},b_{2},...,b_{k}$ in any order, but all of them must be distinct. If there are multiple ways to write out the numbers, choose the one with the maximum number of numbers to write out. If there still are multiple ways, you are allowed to print any of them.
输入输出样例
输入 #1
5 1 2 3 4 5
输出 #1
2 4 5
输入 #2
3 1 2 4
输出 #2
1 4
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted