Pagini recente » Monitorul de evaluare | Cod sursa (job #1194764) | Monitorul de evaluare | Cod sursa (job #2447840) | Cod sursa (job #199974)
Cod sursa(job #199974)
#include <stdio.h>
#include <algorithm>
#define mx 1030
#define bz 1555557
using namespace std;
struct poz
{
long e1, e2;
poz *ua;
} *hash[bz + 4];
long n, l, rez, nr;
long a[mx];
void coh(long loc, long p1, long p2)
{
poz *p;
p = new poz;
p->e1 = p1;
p->e2 = p2;
p->ua = hash[loc];
hash[loc] = p;
}
void ver(long loc, long p1, long p2)
{
for (poz *p = hash[loc]; p; p = p->ua)
if ((p1 != p->e1) && (p2 != p->e1) && (p1 != p->e2) && (p2 != p->e2))
if (a[p1] + a[p2] + a[p->e1] + a[p->e2] == l)
rez++;
}
int main()
{
freopen("oite.in","r",stdin);
freopen("oite.out","w",stdout);
scanf("%ld %ld", &n, &l);
for (int i = 1; i <= n; i++)
scanf("%ld", &a[i]);
for (int i = 1; i < n; i++)
for (int j = i + 1; j <= n; j++)
coh((a[i] + a[j]) % bz, i, j);
for (int i = 1; i < n; i++)
for (int j = i + 1; j <= n; j++)
if (l > a[i] + a[j])
ver((l - a[i] - a[j]) % bz, i, j);
printf("%ld\n", rez / 6);
fclose(stdin);
fclose(stdout);
return 0;
}