QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#623046#8723. 乘二bruteforce_RE 1ms3592kbC++201.3kb2024-10-09 09:47:422024-10-09 09:47:43

Judging History

你现在查看的是最新测评结果

  • [2024-10-09 09:47:43]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3592kb
  • [2024-10-09 09:47:42]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+7,inf=1e18,mod=1e9+7;
int power(int x,int t)
{
	int b=1;
	while(t)
	{
		if(t&1) b=b*x%mod;
		x=x*x%mod; t>>=1;
	}
	return b;
}
void O_o()
{
	int n,k;
	cin>>n>>k;
	int mx=0;
	vector<int> a(n+1),b(n+1);
	for(int i=1; i<=n; i++)
	{
		cin>>a[i];
		mx=max(mx,a[i]);
	}
	int cnt=0;
	for(int i=1; i<=n; i++)
	{
		b[i]=a[i];
		while(b[i]<=mx)
		{
			cnt++;
			b[i]<<=1;
		}
		b[i]>>=1;
		cnt--;
	}
	if(cnt<k)
	{
		priority_queue<int,vector<int>,greater<int>> q;
		for(int i=1; i<=n; i++)
		{
			q.push(a[i]);
		}
		for(int i=1; i<=k; i++)
		{
			int u=q.top(); q.pop();
			q.push(u*2%mod);
		}
		int ans=0;
		while(q.size())
		{
			(ans+=q.top())%=mod;
			q.pop();
		}
		cout<<ans<<"\n";
		return;
	}
	else
	{
		k-=cnt;
		int ans=0;
		sort(b.begin(),b.end());
		int t=k/n,p=k%n;
		for(int i=1; i<=p; i++)
		{
			(ans+=b[i]*power(2,t+1)%mod)%=mod;
		}
		for(int i=p+1; i<=n; i++)
		{
			(ans+=b[i]*power(2,t)%mod)%=mod;
		}
		cout<<ans<<"\n";
	}
}
signed main()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cout<<fixed<<setprecision(12);
	int T=1;
//	cin>>T;
	while(T--)
	{
		O_o();
	}
}















Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3592kb

input:

3 3
7 2 1

output:

15

result:

ok 1 number(s): "15"

Test #2:

score: -100
Runtime Error

input:

200000 1605067
366760624 67854 93901 693975 27016 1046 10808 6533158 54778 500941023 77236442 32173 10431454 2 9726 1553148 89282 411182309 494073 131299543 249904771 7906930 353 9909 3632698 29156 1917186 303 737 1189004 22 1983 263 711 4106258 2070 36704 12524642 5192 123 2061 22887 66 380 1 10153...

output:


result: