Cod sursa(job #609198)

Utilizator andunhillMacarescu Sebastian andunhill Data 19 august 2011 23:15:15
Problema Oite Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.96 kb
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;

#define hash_value 666013
#define mod %666013

ifstream f("oite.in");
ofstream g("oite.out");

struct nod
{	int i,j;
	nod(int ii,int jj)
	{	i = ii; j = jj;
	}
};

vector<nod>hash[hash_value];

int C,L;
int wool[1030];

int countt(int x,int y,int s)
{	int rez = 0,k;
	nod z(0,0);
	for(k = 0; k < hash[s mod].size(); k++)
	{	z.i = hash[s mod][k].i;
		z.j = hash[s mod][k].j;
		if(wool[z.i] + wool[z.j] == s && z.i != x && z.i != y && z.j != x && z.j != y)
			rez++;
	}
	return rez;
}

int main()
{	int i,j,k,nr = 0;
	f>>C>>L;
	for(i = 1; i <= C; i++)
		f>>wool[i];
	sort(wool + 1, wool + C + 1);
	for(i = 1; i <= C; i++)
		for(j = i + 1; j <= C; j++)
			hash[(wool[i] + wool[j])mod].push_back(nod(i,j));
	for(i = 1; i <= C; i++)
		for(j = i + 1; j <= C; j++)
			nr += countt(i, j, L - wool[i] - wool[j]); 
	g<<nr / 6;
	f.close();
	g.close();
	return 0;
}