请求检查输出是否在题目规定的范围内
查看原帖
请求检查输出是否在题目规定的范围内
366897
HarunluoON楼主2023/1/29 16:43

https://www.luogu.com.cn/record/100764128 TLE on #8,90 pts。这份评测记录的代码如下:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
int p[101];
vector<ll> v;
priority_queue<ll,vector<ll> ,greater<ll> > pq;
bool comp(int x,int y)
{
	return x<y;
}
int main()
{
	int n,k,cnt=0;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	scanf("%d",&p[i]),pq.push(p[i]);
	sort(p+1,p+n+1,comp);
	v.push_back(1);
	while(cnt<=k)
	{
		ll qt=pq.top();
		pq.pop();
		if(qt!=v[cnt])
		{
			v.push_back(qt),cnt++;
			for(int i=1;i<=n;i++)
			{
				if(cnt*2>k&&i>5) break;
				if(qt<=2e9/p[i])//qt*p[i]<=2e9 => qt<=2e9/p[i]
				pq.push(qt*p[i]);
			}
		}
	}
//	for(int i=0;i<v.size();i++)
//	printf("%lld ",v[i]);
	printf("%lld",v[k]);
	return 0;
}

将这条用来剪枝的if语句:if(qt<=2e9/p[i])注释掉之后,代码如下(https://www.luogu.com.cn/record/100764652):

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
int p[101];
vector<ll> v;
priority_queue<ll,vector<ll> ,greater<ll> > pq;
bool comp(int x,int y)
{
	return x<y;
}
int main()
{
	int n,k,cnt=0;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	scanf("%d",&p[i]),pq.push(p[i]);
	sort(p+1,p+n+1,comp);
	v.push_back(1);
	while(cnt<=k)
	{
		ll qt=pq.top();
		pq.pop();
		if(qt!=v[cnt])
		{
			v.push_back(qt),cnt++;
			for(int i=1;i<=n;i++)
			{
				if(cnt*2>k&&i>5) break;
//				if(qt<=2e9/p[i])//qt*p[i]<=2e9 => qt<=2e9/p[i]
				pq.push(qt*p[i]);
			}
		}
	}
//	for(int i=0;i<v.size();i++)
//	printf("%lld ",v[i]);
	printf("%lld",v[k]);
	return 0;
}

AC,100 pts。

怀疑是 ansans 大于 2×1092\times10^9 导致原程序中 qtqtvv 只有小于等于 2×1092\times10^9 的数,没有正确答案,因此根本不会有任何输出,所以 TLE 1.20s。

请求检查 #8 测试点输出的 ansans 是否在 [1,2×109][1,2\times10^9] 的范围内。感谢管理员 orz

2023/1/29 16:43
加载中...