CF1188D.Make Equal

NOI/NOI+/CTSC

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given nn numbers a1,a2,…,ana_1, a_2, \dots, a_n. In one operation we can add to any one of those numbers a nonnegative integer power of 22.

What is the smallest number of operations we need to perform to make all nn numbers equal? It can be proved that under given constraints it doesn't exceed 101810^{18}.

给你 nn 个数 a1,a2,…,ana_1, a_2, \dots, a_n。在一次操作中,你可以给其中任意一个数加上一个非负整数次幂的 22(即形如 2k2^k,其中 k≥0k \ge 0 的整数)。

你需要执行的最少操作次数是多少,才能使这 nn 个数全部相等?在本题给定的约束条件下,可以证明答案不会超过 101810^{18}。

输入格式

The first line contains a single integer nn (1≤n≤1051 \le n \le 10^5).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤10170 \le a_i \le 10^{17}).

第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤10170 \le a_i \le 10^{17})。

输出格式

Output exactly one integer — the smallest number of operations we need to perform to make all nn numbers equal.

输出一个整数——使所有 nn 个数相等所需的最少操作次数。

输入输出样例

  • 输入#1

    4
    228 228 228 228

    输出#1

    0
  • 输入#2

    3
    2 2 8

    输出#2

    3

说明/提示

In the first example, all numbers are already equal. So the needed number of operation is 00.

In the second example, we can apply the operation 33 times: add 88 to first 22, add 88 to second 22, add 22 to 88, making all numbers equal to 1010. It can be proved that we can't make all numbers equal in less than 33 operations.

在第一个例子中,所有数字已经相等,因此所需的操作次数为 00。

在第二个例子中,我们可以执行 33 次操作:对第一个 22 加上 88,对第二个 22 加上 88,对 88 加上 22,使得所有数字都等于 1010。可以证明,我们无法用少于 33 次操作使所有数字相等。

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

首页