Pagini recente » Cod sursa (job #2411427) | Cod sursa (job #297097) | Cod sursa (job #2766310) | Cod sursa (job #2824803) | Cod sursa (job #474201)
Cod sursa(job #474201)
#include<stdio.h>
#include<algorithm>
using namespace std;
#define NMAX 1030
#define MOD 666013
#define FIN "oite.in"
#define FOUT "oite.out"
struct hash
{
int x , y;
int lana;
hash* Next;
} *H[MOD + 20];
int C,L,A[NMAX],temp_sum ,REZ = 0,hh;
void insert(int val , int oita1 , int oita2)
{
int h = val % MOD;
hash *hsh = new hash;
hsh -> lana = val;
hsh -> x = oita1;
hsh -> y = oita2;
hsh -> Next = H[h];
H[h] = hsh;
}
void remove(int val)
{
int h = val % MOD;
H[h] = NULL;
}
int main()
{
freopen(FIN , "r" , stdin);
freopen(FOUT , "w" , stdout);
scanf("%d %d\n",&C , &L);
for(int i = 0 ; i < C ;++i)
scanf("%d",&A[i]);
sort(A , A + C);
for(int i = 0 ; i < C ; ++i)
for(int j = i + 1 ; j < C ;++j)
insert(A[i] + A[j] , i , j);
for(int i = 0 ; i < C ;++i)
for(int j = i + 1 ; j < C ;++j)
{
temp_sum = L - A[i] - A[j];
if(temp_sum > 0)
{
hh = temp_sum % MOD;
if(H[hh])
for( hash* tmp = H[hh] ; tmp ; tmp = tmp ->Next)
if(tmp->lana == temp_sum && i != tmp -> x && i != tmp -> y && j != tmp -> x && j != tmp -> y)
REZ++;
}
}
printf("%d",REZ/6);
}