C. Creative Snap
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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 22. 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:
Output the minimum power needed by Thanos to destroy the avengers' base.
Input
The first line contains four integers nn, kk, AA and BB (1≤n≤301≤n≤30, 1≤k≤1051≤k≤105, 1≤A,B≤1041≤A,B≤104), where 2n2n is the length of the base, kkis the number of avengers and AA and BB are the constants explained in the question.
The second line contains kk integers a1,a2,a3,…,aka1,a2,a3,…,ak (1≤ai≤2n1≤ai≤2n), where aiai represents the position of avenger in the base.
Output
Output one integer — the minimum power needed to destroy the avengers base.
Examples
input
Copy
2 2 1 2 1 3
output
Copy
6
input
Copy
3 2 1 2 1 7
output
Copy
8
Note
Consider the first example.
One option for Thanos is to burn the whole base 1−41−4 with power 2⋅2⋅4=162⋅2⋅4=16.
Otherwise he can divide the base into two parts 1−21−2 and 3−43−4.
For base 1−21−2, he can either burn it with power 2⋅1⋅2=42⋅1⋅2=4 or divide it into 22 parts 1−11−1 and 2−22−2.
For base 1−11−1, he can burn it with power 2⋅1⋅1=22⋅1⋅1=2. For 2−22−2, he can destroy it with power 11, as there are no avengers. So, the total power for destroying 1−21−2 is 2+1=32+1=3, which is less than 44.
Similarly, he needs 33 power to destroy 3−43−4. The total minimum power needed is 66.
放假太划水 回来水题练手先
这题主要是看k范围,虽然区间为1-1e9,但是由于k只有5次方,很多区间都是没有avengers的,所以直接暴力就行。
#include
using namespace std;
typedef long long ll;
ll num,sum,t,n,m,x,y,k;
ll a[100005];
ll dfs(int l,int r){
ll ans;
ll len=upper_bound(a+1,a+k+1,r)-lower_bound(a+1,a+k+1,l);
if(!len)
return ans=x;
else
ans=(r-l+1)*len*y;
if(r-l<1)
return ans;
ll mid=(l+r)/2;
ans=min(ans,dfs(l,mid)+dfs(mid+1,r));
return ans;
}
int main(){
ll i,j,l,r;
while(~scanf("%lld%lld%lld%lld",&n,&k,&x,&y)){
for(i=1;i<=k;i++)
scanf("%lld",&a[i]);
sort(a+1,a+k+1);
num=1;
while(n--)
num*=2;
ll ans=dfs(1,num);
printf("%lld\n",ans);
}
return 0;
}