Cod sursa(job #548072)

Utilizator ConsstantinTabacu Raul Consstantin Data 7 martie 2011 08:06:09
Problema Oite Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include<stdio.h>
#include<vector>
#define H1 666013
#define Nmax 1034
using namespace std;
struct hash{int s,a,b;}aux;

vector<hash> h1[ H1 ];

int n,m,i,sol,j,k,l,v[ Nmax ];

void citire(){
freopen("oite.in","r",stdin);
scanf("%d %d",&n,&l);
int i;
for(i = 1 ; i <= n;  i++)
	scanf("%d ",&v[i]);

}

void solve(){
int i,j,s,N1,t,hh1;

for(i = 1;i <= n; i++)
	for(j = i+1;j<=n;j++)
		{s = v[i] + v[j];
		aux.s = s;
		aux.a = i;
		aux.b = j;
		h1[ s % H1 ].push_back(aux);
		}
	
for(i = 1 ;i <= n ; i++)
 	for(j = i+1;j<=n;j++)
		{s = l- v[i] - v[j];
		if(s < 0)continue;
		hh1 = s % H1;
		N1 = h1[ hh1 ].size();
		
		for(t = 0;t < N1 ; t++)
			{aux = h1[ hh1 ][ t ];
			if(aux.s == s && i != aux.a && i != aux.b && j!= aux.a && j != aux.b)
				{sol++;
				}
			}
		}
		

}

void afisare(){
freopen("oite.out","w",stdout);
printf("%d ",sol/6);

}

int main(){
citire();
solve();
afisare();
return 0;}