A7751 | Creative Snap
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $2$ . Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following:
- if the current length is at least $2$ , divide the base into $2$ equal halves and destroy them separately, or
- burn the current base. If it contains no avenger in it, it takes $A$ amount of power, otherwise it takes his $B \cdot n_a \cdot l$ amount of power, where $n_a$ is the number of avengers and $l$ is the length of the current base.
Output the minimum power needed by Thanos to destroy the avengers' base.
Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length of their base is a perfect power of $2$ . Thanos wants to destroy the base using minimum power. He starts with the whole base and in one step he can do either of following:
- if the current length is at least $2$ , divide the base into $2$ equal halves and destroy them separately, or
- burn the current base. If it contains no avenger in it, it takes $A$ amount of power, otherwise it takes his $B \cdot n_a \cdot l$ amount of power, where $n_a$ is the number of avengers and $l$ is the length of the current base.
Output the minimum power needed by Thanos to destroy the avengers' base.
输入格式
The first line contains four integers $n$ , $k$ , $A$ and $B$ ( $1 \leq n \leq 30$ , $1 \leq k \leq 10^5$ , $1 \leq A,B \leq 10^4$ ), where $2^n$ is the length of the base, $k$ is the number of avengers and $A$ and $B$ are the constants explained in the question.
The second line contains $k$ integers $a_{1}, a_{2}, a_{3}, \ldots, a_{k}$ ( $1 \leq a_{i} \leq 2^n$ ), where $a_{i}$ represents the position of avenger in the base.
The second line contains $k$ integers $a_{1}, a_{2}, a_{3}, \ldots, a_{k}$ ( $1 \leq a_{i} \leq 2^n$ ), where $a_{i}$ represents the position of avenger in the base.
输出格式
Output one integer — the minimum power needed to destroy the avengers base.
输入输出样例
输入 #1
2 2 1 2 1 3
输出 #1
6
输入 #2
3 2 1 2 1 7
输出 #2
8
Consider the first example.
One option for Thanos is to burn the whole base $1-4$ with power $2 \cdot 2 \cdot 4 = 16$ .
Otherwise he can divide the base into two parts $1-2$ and $3-4$ .
For base $1-2$ , he can either burn it with power $2 \cdot 1 \cdot 2 = 4$ or divide it into $2$ parts $1-1$ and $2-2$ .
For base $1-1$ , he can burn it with power $2 \cdot 1 \cdot 1 = 2$ . For $2-2$ , he can destroy it with power $1$ , as there are no avengers. So, the total power for destroying $1-2$ is $2 + 1 = 3$ , which is less than $4$ .
Similarly, he needs $3$ power to destroy $3-4$ . The total minimum power needed is $6$ .
One option for Thanos is to burn the whole base $1-4$ with power $2 \cdot 2 \cdot 4 = 16$ .
Otherwise he can divide the base into two parts $1-2$ and $3-4$ .
For base $1-2$ , he can either burn it with power $2 \cdot 1 \cdot 2 = 4$ or divide it into $2$ parts $1-1$ and $2-2$ .
For base $1-1$ , he can burn it with power $2 \cdot 1 \cdot 1 = 2$ . For $2-2$ , he can destroy it with power $1$ , as there are no avengers. So, the total power for destroying $1-2$ is $2 + 1 = 3$ , which is less than $4$ .
Similarly, he needs $3$ power to destroy $3-4$ . The total minimum power needed is $6$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted