Cod sursa(job #53472)

Utilizator alextheroTandrau Alexandru alexthero Data 22 aprilie 2007 11:25:18
Problema Oite Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <stdio.h>
#include <string.h>
#include <vector>

#define cmax 1024
#define mod 666313

#define pb push_back

using namespace std;

typedef pair<int,int> ii;

int c,l,tot,i,j;
int a[cmax];
vector <ii> hs[mod];

inline int hash(int x) {
	return x % mod;
}

void add(int x) {
	int p1 = hash(x);
	for(int i = 0; i < (int)hs[p1].size(); i++)
		if(hs[p1][i].first == x) {
			hs[p1][i] = ii(x,hs[p1][i].second + 1);
			return ;
		}
	hs[p1].pb(ii(x,1));
}

inline int hsh(int x) {
	int p1 = hash(x);
	for(int i = 0; i < (int)hs[p1].size(); i++)
		if(hs[p1][i].first == x) return hs[p1][i].second;
	return 0;
}

int main() {
	freopen("oite.in","r",stdin);
	freopen("oite.out","w",stdout);

	scanf("%d%d",&c,&l);
	for(i = 0; i < c; i++) scanf("%d",&a[i]);

	memset(hs,0,sizeof(hs));

	for(i = 0; i < c; i++) { 
		for(j = i + 1; j < c; j++) 
			if(l - (a[i] + a[j]) >= 0) 
				tot += hsh(l - (a[i] + a[j]));
		for(j = 0; j < i; j++) 
			add(a[i] + a[j]);
	}

	printf("%d\n",tot);
	return 0;
}