Cod sursa(job #940715)

Utilizator Cosmin1490Balan Radu Cosmin Cosmin1490 Data 16 aprilie 2013 23:06:44
Problema Oite Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.58 kb
#include <stdlib.h>
#include <fstream>
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <string.h>
#include <iomanip>
#include <time.h>
#include <list>
#include <algorithm>
#include <math.h>
#include <assert.h>
using namespace std;


const string file = "oite";

const string infile = file + ".in";
const string outfile = file + ".out";

typedef unsigned int UINT;

UINT ANS;
UINT L, N;
vector<UINT> A;



const int MOD = 50101;
vector<pair<UINT, UINT> > HM[MOD + 5];

inline UINT cHash(UINT i)
{
	return i % MOD;
}


UINT Find(UINT v)
{
	int h = cHash(v);
	for (vector<pair<UINT, UINT> > ::iterator itr = HM[h].begin();
		 itr != HM[h].end();
		 itr++)
	{
		if(itr->first == v)
		{
			return itr->second;
		}
	}
	return 0;

}

void Add(UINT v)
{
	int h = cHash(v);
	for (vector<pair<UINT, UINT> > ::iterator itr = HM[h].begin();
		itr != HM[h].end();
		itr++)
	{
		if(itr->first == v)
		{
			itr->second ++;
			return;
		}
	}
	HM[h].push_back(make_pair(v, 1));
}

void citire()
{
	ifstream fin(infile.c_str());

	fin >> N >> L;
	A.resize(N, 0);
	

	for(UINT i = 0; i < N; i++)
	{
		fin >> A[i];
	}
	

	fin.close();
}

void solve()
{
	for(UINT i = 0; i < N; i++)
	{

		for(UINT j = i + 1; j < N; j++)
		{
			ANS += Find(L- A[i] - A[j]);
		}

		for(UINT j = 0; j < i; j++)
		{
			Add(A[i] + A[j]);
		}
	}
}

void afisare()
{
	ofstream fout(outfile.c_str());

	fout << ANS << "\n";

	fout.close();
}

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