换了一种思路避免RE,结果TLE了。帮忙改一下吧,玄关
查看原帖
换了一种思路避免RE,结果TLE了。帮忙改一下吧,玄关
931492
xiaohuanxiong楼主2024/3/25 22:04
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+1;
long long n,c,x[N]={},y[N][2]={},len=0,ans=0;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>c;
	for (int i=1;i<=n;i++)
		cin>>x[i];
	sort(x+1,x+n+1);
	for (int i=1;i<=n;i++)
	{
		if (x[i]!=x[i-1])
		{
			len++;
			y[len][0]=x[i];
		}	
		y[len][1]+=1;
	}
	for (int i=1;i<=len;i++)
	{
		for (int j=i+1;j<=len;j++)
			if (y[i][0]+c==y[j][0])
			{
				ans+=y[i][1]*y[j][1];
				break;
			}	
	}
	cout<<ans;
 	return 0;
}
2024/3/25 22:04
加载中...