Cod sursa(job #474532)

Utilizator Bogdan_tmmTirca Bogdan Bogdan_tmm Data 4 august 2010 00:01:30
Problema Oite Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include<algorithm>
#include<vector>
using namespace std;
#define N_MAX 1030

int n,l,i,j,k,sol;
int a[N_MAX];
#define H 9001

struct p
{
	int i,j,s;
	p()
	{
	}
	p(const int i,const int j,const int s)
	{
		this->i=i;
		this->j=j;
		this->s=s;
	}
};
vector <p> hash[H];
vector <p> ::iterator it;

int main()
{
	freopen("oite.in","r",stdin);
	freopen("oite.out","w",stdout);
	
	scanf("%d%d",&n,&l);

	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	
	for(i=1;i<=n;i++)
		for(j=i+1;j<=n;j++)
		{
			int s=a[i]+a[j];
			hash[s%H].push_back(p(i,j,s));
		}

	int s,s1,hs;
	for(i=1;i<=n;i++)
	{
		for(j=i+1;j<=n;j++)
		{
			s1=a[i]+a[j];
			if(s1>l)
				break;
			s=l-s1;
			hs=s%H;
			for(it=hash[hs].begin();it!=hash[hs].end();it++)
				if(it->s==s)
					if(j<it->i)
						++sol;
		}
	}
		
	printf("%d\n",sol);

	return 0;
}