A13747 | Power Sequence
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Let's call a list of positive integers $a_0, a_1, ..., a_{n-1}$ a power sequence if there is a positive integer $c$ , so that for every $0 \le i \le n-1$ then $a_i = c^i$ .
Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$ , you are allowed to:
- Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$ ), then
- Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$ ) with a cost of $1$ .
Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence.
Given a list of $n$ positive integers $a_0, a_1, ..., a_{n-1}$ , you are allowed to:
- Reorder the list (i.e. pick a permutation $p$ of $\{0,1,...,n - 1\}$ and change $a_i$ to $a_{p_i}$ ), then
- Do the following operation any number of times: pick an index $i$ and change $a_i$ to $a_i - 1$ or $a_i + 1$ (i.e. increment or decrement $a_i$ by $1$ ) with a cost of $1$ .
Find the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence.
输入格式
The first line contains an integer $n$ ( $3 \le n \le 10^5$ ).
The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ( $1 \le a_i \le 10^9$ ).
The second line contains $n$ integers $a_0, a_1, ..., a_{n-1}$ ( $1 \le a_i \le 10^9$ ).
输出格式
Print the minimum cost to transform $a_0, a_1, ..., a_{n-1}$ into a power sequence.
输入输出样例
输入 #1
3 1 3 2
输出 #1
1
输入 #2
3 1000000000 1000000000 1000000000
输出 #2
1999982505
In the first example, we first reorder $\{1, 3, 2\}$ into $\{1, 2, 3\}$ , then increment $a_2$ to $4$ with cost $1$ to get a power sequence $\{1, 2, 4\}$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted