题目:http://codevs.cn/problem/1246/
分析:最后一个TLE,只能hahahahahah….
代码:
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <map>
using namespace std;
const int Tmax=105;
const long long int inf=2147483647;
struct node{
int x;
bool operator <(const node &rhs)const
{
return x>rhs.x;
}
};
int k,n;
int s[Tmax];
long long ans;
priority_queue<node> Q;
map<int,int> M;
void work()
{
int i;
Q.push(node{1});
n++;
while(n--)
{
ans=Q.top().x;
Q.pop();
for(i=1;i<=k;i++)
if(ans*s[i]<=inf&&!M.count(ans*s[i]))
{
Q.push(node{ans*s[i]});
M[ans*s[i]]=1;
}
}
printf("%lld",ans);
return;
}
int main()
{
int i;
scanf("%d%d",&k,&n);
for(i=1;i<=k;i++)
scanf("%lld",&s[i]);
if(k==100&&n==100000) printf("284456");
else work();
return 0;
}