Pagini recente » Cod sursa (job #1308731) | Cod sursa (job #1572973) | Cod sursa (job #2172667) | Cod sursa (job #1038409) | Cod sursa (job #968196)
Cod sursa(job #968196)
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define CMAX 1025
#define MOD 666013
int HashValue, SearchValue;
struct nod {
int S;
int ap;
vector <int> D;
nod *next;
};
nod *H[MOD + 3];
vector <int> Dct(3);
bool a[CMAX][CMAX];
void add(int i, int Sum, int Ap) {
nod *p = new nod;
p->S = Sum;
p->ap = Ap;
p->D = Dct;
p->next = H[i];
H[i] = p;
}
int c, L, i, j, Csum, n;
int C[CMAX];
int ANS, c1, c2;
struct oite{int v, e1, e2;}Suma[CMAX * CMAX];
int Search_HashValue(int X) {
for (nod *it = H[X]; it; it = it->next)
if (it->S == Csum){++it->ap; return 1;}
return 0;
}
void Search_Hash(int X) {
for (nod *it = H[X]; it; it = it->next) {
if (it->D[1] != Dct[1] && it->D[1] != Dct[2] && it->D[2] != Dct[1] && it->D[2] != Dct[2])
ANS += it->ap;
}
}
int main() {
freopen("oite.in","r",stdin);
freopen("oite.out","w",stdout);
scanf("%i%i", &c, &L);
for (i = 1; i <= c; ++i)
scanf("%i", &C[i]);
for (i = 1; i <= c; ++i) {
for (j = 1; j <= c; ++j) {
if (i != j && !a[i][j]) {
Csum = C[i] + C[j];
Suma[++n].v = Csum;
Suma[n].e1 = Dct[1] = i;
Suma[n].e2 = Dct[2] = j;
a[i][j] = a[j][i] = true;
HashValue = Csum % MOD;
if (!Search_HashValue(HashValue))
add(HashValue, Csum, 1);
}
}
}
for (i = 1; i <= n; ++i) {
SearchValue = L - Suma[i].v;
if (SearchValue < 0) continue;
Dct[1] = Suma[i].e1;
Dct[2] = Suma[i].e2;
HashValue = SearchValue % MOD;
Search_Hash(HashValue);
}
printf("%i\n", ANS/6);
return 0;
}