QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#416419 | #8723. 乘二 | yangyuchen17 | RE | 0ms | 0kb | C++14 | 1.2kb | 2024-05-21 20:24:03 | 2024-05-21 20:24:03 |
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=2e5+5,mod=1e9+7;
LL n,a[N],k,ans[N];
LL qp(LL a,LL b){
LL res=1,i=a;
while(b){
if(b&1) res=(res*i)%mod;
i=(i*i)%mod;
b>>=1;
}
return res%mod;
}
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+1+n);
for(int i=2;i<=n;i++){
int l=0,r=33;
while(l<r){
int mid=l+r>>1;
if(a[i-1]*(1ll<<mid)<a[i]) l=mid+1;
else r=mid;
}
if(k>i*l){
k-=i*l;
ans[i-1]=l;
}else{
ans[i-1]=k/i;
k%=i;
while(k--){
a[i]<<=1;
i--;
}
break;
}
}
if(k){
ans[n]+=k/n;
k%=n;
LL x=n;
while(k--){
a[x]=(a[x]<<1)%mod;
x--;
}
}
for(int i=n-1;i>=1;i--){
ans[i]+=ans[i+1];
}
for(int i=1;i<=n;i++){
ans[0]=(ans[0]+(a[i]*qp(1ll*2,ans[i]))%mod)%mod;
}
cout<<ans[0];
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 3 7 2 1