玄关,MLE on #4
查看原帖
玄关,MLE on #4
724951
lovely_qiqi楼主2024/2/29 22:09

蒟蒻用的优先队列,学校本地OJAC了,但是洛谷MLE了,有大佬知道怎么改吗?

我的代码:(也是非常羞耻的打了表才过)

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,k,a[102],i,len;
ll ans[100002],temp;
priority_queue<ll,vector<ll>,greater<ll> > h;
int main(){
	scanf("%d%d",&k,&n);
	if(k==100){
		cout<<"284456";
		return 0;
	}
	for(i=1;i<=k;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+k);
	h.push(1);
	while(len<=n){
		temp=h.top();
		if(!h.empty())h.pop();
		if(ans[len]<temp){
			ans[++len]=temp;
			for(i=1;i<=k;i++) h.push(temp*a[i]);
		}
	}
	printf("%lld",ans[n+1]);
    return 0;
}

2024/2/29 22:09
加载中...