CF1397B.Power Sequence

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Let's call a list of positive integers a0,a1,...,an−1a_0, a_1, ..., a_{n-1} a power sequence if there is a positive integer cc, so that for every 0≤i≤n−10 \le i \le n-1 then ai=cia_i = c^i.

Given a list of nn positive integers a0,a1,...,an−1a_0, a_1, ..., a_{n-1}, you are allowed to:

  • Reorder the list (i.e. pick a permutation pp of 0,1,...,n−1{0,1,...,n - 1} and change aia_i to apia_{p_i}), then
  • Do the following operation any number of times: pick an index ii and change aia_i to ai−1a_i - 1 or ai+1a_i + 1 (i.e. increment or decrement aia_i by 11) with a cost of 11.

Find the minimum cost to transform a0,a1,...,an−1a_0, a_1, ..., a_{n-1} into a power sequence.

我们称一个正整数序列 a0,a1,...,an−1a_0, a_1, ..., a_{n-1} 为幂序列,当且仅当存在某个正整数 cc,使得对每个 0≤i≤n−10 \le i \le n-1 都有 ai=cia_i = c^i。

给定一个包含 nn 个正整数的序列 a0,a1,...,an−1a_0, a_1, ..., a_{n-1},你可以执行以下操作:

  • 重排序列(即选取 {0,1,...,n−1}\{0,1,...,n - 1\} 的一个排列 pp,并将每个 aia_i 替换为 apia_{p_i}),然后
  • 任意次执行如下操作:选取一个下标 ii,将 aia_i 修改为 ai−1a_i - 1 或 ai+1a_i + 1(即对 aia_i 加 11 或减 11),每次操作代价为 11。

求将序列 a0,a1,...,an−1a_0, a_1, ..., a_{n-1} 变为一个幂序列所需的最小总代价。

输入格式

The first line contains an integer nn (3≤n≤1053 \le n \le 10^5).

The second line contains nn integers a0,a1,...,an−1a_0, a_1, ..., a_{n-1} (1≤ai≤1091 \le a_i \le 10^9).

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

第二行包含 nn 个整数 a0,a1,...,an−1a_0, a_1, ..., a_{n-1}(1≤ai≤1091 \le a_i \le 10^9)。

输出格式

Print the minimum cost to transform a0,a1,...,an−1a_0, a_1, ..., a_{n-1} into a power sequence.

输出将 a0,a1,...,an−1a_0, a_1, ..., a_{n-1} 变为幂序列的最小代价。

输入输出样例

  • 输入#1

    3
    1 3 2

    输出#1

    1
  • 输入#2

    3
    1000000000 1000000000 1000000000

    输出#2

    1999982505

说明/提示

In the first example, we first reorder 1,3,2{1, 3, 2} into 1,2,3{1, 2, 3}, then increment a2a_2 to 44 with cost 11 to get a power sequence 1,2,4{1, 2, 4}.

在第一个例子中,我们首先将 {1,3,2}\{1, 3, 2\} 重排为 {1,2,3}\{1, 2, 3\},然后以代价 11 将 a2a_2 增加至 44,从而得到一个幂序列 {1,2,4}\{1, 2, 4\}。

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

首页