Pagini recente » Cod sursa (job #2854509) | Cod sursa (job #964863) | Cod sursa (job #775141) | Cod sursa (job #2891425) | Cod sursa (job #64420)
Cod sursa(job #64420)
#include <cstdio>
#include <algorithm>
#define MOD 312457
#define pow(x) (1u<<(x))
#define f(x) ((x) & ((1<<22)-1))
#define set(x) mask[f(x)/32] |= pow(f(x) & 31)
#define ok(x) (mask[f(x)/32] & pow(f(x) & 31))
using namespace std;
struct rec {
unsigned p, val, nr;
};
unsigned n, sol;
unsigned s, a[1200], aloc = MOD, mask[1<<19];
rec h[MOD+(1<<20)];
void baga(unsigned x)
{
set(x);
unsigned key = x%MOD;
while (h[key].p){
if (h[key].val == x){
h[key].nr++;
return;
}
key=h[key].p;
}
h[key].p = aloc++;
h[key].val = x;
h[key].nr = 1;
}
unsigned count(unsigned x)
{
if (!ok(x)) return 0;
unsigned key = x%MOD;
while (h[key].p){
if (h[key].val==x) return h[key].nr;
key=h[key].p;
}
return 0;
}
int main()
{
freopen("oite.in", "r", stdin);
freopen("oite.out", "w", stdout);
scanf("%u %u", &n, &s);
unsigned i,k;
for (i=0; i<n; i++)
scanf("%u", a+i);
sort(a, a+n);
reverse(a+n, a);
for (k=2; k<n-1; k++){
for (i=0; i<k-1; i++)
baga(a[k-1]+a[i]);
for (i=k+1; i<n; i++)
sol += count(s-a[k]-a[i]);
}
printf("%u\n", sol);
return 0;
}