QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#465332 | #8723. 乘二 | ukuk | RE | 0ms | 0kb | C++14 | 1.8kb | 2024-07-06 20:06:47 | 2024-07-06 20:06:47 |
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define i64 long long
#define LL long long
#define i128 __int128
#define ull unsigned long long
#define db long double
#define PII pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define lowbit(x) ((x)&-(x))
#define debug(x) cout<<(#x)<<" = "<<(x)<<'\n'
const double eps=1e-8;
const int mod=1e9+7;
//const int mod=998244353;
const int inf=1e9+7;
const i64 INF=1e9+7;
const int N=2e5+5;
const int M=1e6+5;
//const int g=3;
//const int gi=332748118;
LL qmi(LL a,int b){
a=(a%mod+mod)%mod;
LL ret=1;
for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;
return ret;
}
int Sqrt(int x){
assert(x>=0);
int t=sqrt(x);
while((t+1)*(t+1)<=x)t++;
while(t*t>x)t--;
return t;
}
int lcm(int x,int y){
if(!x||!y)return x+y;
return x/__gcd(x,y)*y;
}
int n;
int k;
int len(int x){
for(int i=0;i;i++){
if(!(x>>i))return i;
}
}
inline void solve(){
cin>>n>>k;
assert(n==3);
cout<<k<<'\n';
priority_queue<int,vector<int>,greater<int>>q;
int h=0;
for(int i=0;i<n;i++){
// cout<<"OK\n";
int x;cin>>x;
q.push(x);
h=max(h,len(x));
}
debug(h);
debug(q.size());
vector<int>a;
while(k&&q.size()){
int x=q.top();q.pop();
debug(x);
if(len(x)==h)a.pb(x);
else k--,x<<=1,q.push(x);
}
while(q.size()){
a.pb(q.top());
q.pop();
}
sort(all(a));
int ans=0;
for(int i=0;i<a.size();i++){
int c=k/a.size();
if(i+1<=k%a.size())c++;
// debug(a[i]);
// debug(c);
ans+=a[i]*qmi(2,c)%mod;
ans%=mod;
}
debug(ans);
debug(k);
for(int x:a)debug(x);
cout<<ans;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int _=1;
// cin>>_;
while(_--)solve();
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