Cod sursa(job #1742363)

Utilizator Kln1000Ciobanu Bogdan Kln1000 Data 16 august 2016 12:55:32
Problema Oite Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cstring>
///WIP///

using namespace std;

ifstream f ("oite.in");
ofstream t ("oite.out");

int32_t c,l,s=0;
const int key=47,mod=1049000;

vector <int32_t> v;
int32_t hsh[mod+1];

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 hash_erase(int32_t x){int32_t i=hashsum(x);
for (;hsh[i]!=x;increment(i));
hsh[i]=-1;
}

void spoof(){
for (int32_t k=2;k<c-1;++k){
for (int32_t y=k+1;y<c;++y){
for (int32_t i=0;i<k-1;++i){
for (int32_t j=i+1;j<k;++j)
hash_add(v[i]+v[j]);
}
s+=hash_find(l-v[k]-v[y]);}}}

int main()
{f>>c>>l;
v.resize(c);
for (int i=0;i<c;++i)
f>>v[i];
sort(v.begin(),v.end());
spoof();
t<<s;
return 0;
}