社区讨论

求助!#4TLE

P2723[USACO3.1] 丑数 Humble Numbers参与者 2已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@lo85hns6
此快照首次捕获于
2023/10/27 13:06
2 年前
此快照最后确认于
2023/10/27 13:06
2 年前
查看原帖
CPP
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <cstdio>
using namespace std;
typedef long long LL;
int a[101];
priority_queue<LL,vector<LL>,greater<LL> >pq;
set<LL>s;
int main(){
	int K,N;
	cin>>K>>N;
	for(int i=1;i<=K;i++)
		cin>>a[i];
	pq.push(1);
	s.insert(1);
	for(int i=1;;i++){
		LL x=pq.top();
		pq.pop();
		if(i==N+1){
			cout<<x<<endl;
			break;
		}
		for(int j=1;j<=K;j++){
			LL x2=x*a[j];
			if(!s.count(x2)){s.insert(x2);pq.push(x2);}
		}
	}
	return 0;
} 

回复

1 条回复,欢迎继续交流。

正在加载回复...