Pagini recente » Cod sursa (job #1546449) | Cod sursa (job #258317) | Cod sursa (job #811048) | Cod sursa (job #1887328) | Cod sursa (job #1749939)
#include <iostream>
#include <fstream>
#include <cstring>
#define BYTE 0xff+1
#define getByte(X,Y) (*(((unsigned char *)&X)+Y))
#define NR_BYTES (sizeof(uint32_t))
#define MAX_N 10000000 + 1
using namespace std;
ifstream f ("oite.in");
ofstream t ("oite.out");
uint32_t c,l,s=0;
const int key=47,mod=1049000;
int32_t v[1028];
int32_t hsh[mod+10];
void increment(int32_t &i)
{
if (++i==mod) i=0;
}
int32_t hashsum(int32_t x)
{
return (1LL*x*key+x/key)%mod;
}
void hash_add(int32_t x)
{
int32_t i=hashsum(x);
for (; hsh[i]!=0; increment(i));
hsh[i]=x;
}
int32_t hash_find(int32_t x)
{
int32_t cnt=0,i=hashsum(x);
for (; hsh[i]!=0; increment(i))
if (hsh[i]==x) ++cnt;
return cnt;
}
void spoof()
{
for (unsigned int i = 1; i < c; ++i) {
for (unsigned int j = i + 1; j < c; ++j)
s += hash_find(l - v[i] - v[j]);
for (unsigned int j = 0; j < i; ++j)
hash_add(v[i] + v[j]);
}
}
int main()
{
f>>c>>l;
for (uint16_t i=0; i<c; ++i)
f>>v[i];
spoof();
t<<s;
return 0;
}