Pagini recente » Cod sursa (job #1695615) | Cod sursa (job #3126319) | Cod sursa (job #49170) | Cod sursa (job #664014) | Cod sursa (job #1749947)
#include <iostream>
#include <fstream>
#include <cstring>
#define BYTE 0xff+1
#define getByte(X,Y) (*(((unsigned char *)&X)+Y))
#define NR_BYTES (sizeof(uint_fast32_t))
#define MAX_N 10000000 + 1
using namespace std;
ifstream f ("oite.in");
ofstream t ("oite.out");
int_fast32_t c,l,s=0;
const int key=21313,mod=1049000;
int_fast32_t v[1028];
pair <int_fast32_t,int_fast32_t> hsh[mod+10];
void increment(int_fast32_t &i)
{
if (++i==mod) i=0;
}
int_fast32_t hashsum(int_fast32_t x)
{
return (1LL*x*key+x/key)%mod;
}
void hash_add(int_fast32_t x)
{
int_fast32_t i=hashsum(hashsum(x));
for (; hsh[i].first!=x and hsh[i].first!=0; increment(i));
if (hsh[i].first==0){
hsh[i].first=x;
hsh[i].second=1;}
else ++hsh[i].second;
}
int_fast32_t hash_find(int_fast32_t x)
{
int_fast32_t cnt=0,i=hashsum(hashsum(x));
for (; hsh[i].first!=0 and hsh[i].first!=x; increment(i));
if (hsh[i].first==x) cnt+=hsh[i].second;
return cnt;
}
void spoof()
{
for (int i = 1; i < c; ++i) {
for (int j = i + 1; j < c; ++j)
if (l-v[i]-v[j]>=0)
s += hash_find(l - v[i] - v[j]);
for (int j = 0; j < i; ++j)
hash_add(v[i] + v[j]);
}
}
int main()
{ ios_base::sync_with_stdio(false);
f>>c>>l;
for (uint_fast16_t i=0; i<c; ++i)
f>>v[i];
spoof();
t<<s;
return 0;
}