A14675 | Christmas Chocolates
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Christmas is coming, Icy has just received a box of chocolates from her grandparents! The box contains $n$ chocolates. The $i$ -th chocolate has a non-negative integer type $a_i$ .
Icy believes that good things come in pairs. Unfortunately, all types of chocolates are distinct (all $a_i$ are distinct). Icy wants to make at least one pair of chocolates the same type.
As a result, she asks her grandparents to perform some chocolate exchanges. Before performing any chocolate exchanges, Icy chooses two chocolates with indices $x$ and $y$ ( $1 \le x, y \le n$ , $x \ne y$ ).
In a chocolate exchange, Icy's grandparents choose a non-negative integer $k$ , such that $2^k \ge a_x$ , and change the type of the chocolate $x$ from $a_x$ to $2^k - a_x$ (that is, perform $a_x := 2^k - a_x$ ).
The chocolate exchanges will be stopped only when $a_x = a_y$ . Note that other pairs of equal chocolate types do not stop the procedure.
Icy's grandparents are smart, so they would choose the sequence of chocolate exchanges that minimizes the number of exchanges needed. Since Icy likes causing trouble, she wants to maximize the minimum number of exchanges needed by choosing $x$ and $y$ appropriately. She wonders what is the optimal pair $(x, y)$ such that the minimum number of exchanges needed is maximized across all possible choices of $(x, y)$ .
Since Icy is not good at math, she hopes that you can help her solve the problem.
Icy believes that good things come in pairs. Unfortunately, all types of chocolates are distinct (all $a_i$ are distinct). Icy wants to make at least one pair of chocolates the same type.
As a result, she asks her grandparents to perform some chocolate exchanges. Before performing any chocolate exchanges, Icy chooses two chocolates with indices $x$ and $y$ ( $1 \le x, y \le n$ , $x \ne y$ ).
In a chocolate exchange, Icy's grandparents choose a non-negative integer $k$ , such that $2^k \ge a_x$ , and change the type of the chocolate $x$ from $a_x$ to $2^k - a_x$ (that is, perform $a_x := 2^k - a_x$ ).
The chocolate exchanges will be stopped only when $a_x = a_y$ . Note that other pairs of equal chocolate types do not stop the procedure.
Icy's grandparents are smart, so they would choose the sequence of chocolate exchanges that minimizes the number of exchanges needed. Since Icy likes causing trouble, she wants to maximize the minimum number of exchanges needed by choosing $x$ and $y$ appropriately. She wonders what is the optimal pair $(x, y)$ such that the minimum number of exchanges needed is maximized across all possible choices of $(x, y)$ .
Since Icy is not good at math, she hopes that you can help her solve the problem.
输入格式
The first line of the input contains a single integer $n$ ( $2 \le n \le 2 \cdot 10^5$ ) — the number of chocolates.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ( $0 \le a_i \le 10^9$ ).
It is guaranteed that all $a_i$ are distinct.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ( $0 \le a_i \le 10^9$ ).
It is guaranteed that all $a_i$ are distinct.
输出格式
Output three integers $x$ , $y$ , and $m$ .
$x$ and $y$ are indices of the optimal chocolates to perform exchanges on. Your output must satisfy $1 \le x, y \le n$ , $x \ne y$ .
$m$ is the number of exchanges needed to obtain $a_x = a_y$ . We can show that $m \le 10^9$ for any pair of chocolates.
If there are multiple solutions, output any.
$x$ and $y$ are indices of the optimal chocolates to perform exchanges on. Your output must satisfy $1 \le x, y \le n$ , $x \ne y$ .
$m$ is the number of exchanges needed to obtain $a_x = a_y$ . We can show that $m \le 10^9$ for any pair of chocolates.
If there are multiple solutions, output any.
输入输出样例
输入 #1
5 5 6 7 8 9
输出 #1
2 5 5
输入 #2
2 4 8
输出 #2
1 2 2
In the first test case, the minimum number of exchanges needed to exchange a chocolate of type $6$ to a chocolate of type $9$ is $5$ . The sequence of exchanges is as follows: $6 \rightarrow 2 \rightarrow 0 \rightarrow 1 \rightarrow 7 \rightarrow 9$ .
In the second test case, the minimum number of exchanges needed to exchange a chocolate of type $4$ to a chocolate of type $8$ is $2$ . The sequence of exchanges is as follows: $4 \rightarrow 0 \rightarrow 8$ .
In the second test case, the minimum number of exchanges needed to exchange a chocolate of type $4$ to a chocolate of type $8$ is $2$ . The sequence of exchanges is as follows: $4 \rightarrow 0 \rightarrow 8$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted