Cod sursa(job #1742343)

Utilizator Kln1000Ciobanu Bogdan Kln1000 Data 16 august 2016 12:41:54
Problema Oite Scor 10
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");

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

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

void increment(int &i){
if (++i==mod) i=0;}

int hashsum(int x){
return (1LL*x*key+x/key)%mod;}

void hash_add(int x){int i=hashsum(x);
for (;hsh[i]!=0;increment(i));
hsh[i]=x;
}

int hash_find(int x){int cnt=0,i=hashsum(x);
for (;hsh[i]!=0;increment(i))
if (hsh[i]==x) ++cnt;
return cnt;
}

void hash_erase(int x){int i=hashsum(x);
for (;hsh[i]!=x;increment(i));
hsh[i]=-1;
}

void spoof(){
for (volatile int i=2;i<c-1;++i){
for (volatile int j=i+1;j<c;++j)
hash_add(v[i]+v[j]);
for (volatile int k=0;k<i-1;++k){
for (volatile int y=k+1;y<i;++y)
s+=hash_find(l-v[k]-v[y]);
}
memset(hsh,0,sizeof(hsh));}}

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;
}