Pagini recente » Cod sursa (job #3004440) | Cod sursa (job #2856175) | Cod sursa (job #1054627) | Cod sursa (job #337377) | Cod sursa (job #339988)
Cod sursa(job #339988)
#include<fstream>
#define p 500009
using namespace std;
struct nod{
int inf,x,y;
nod *urm;};
nod *hash[500009];
void add(int val,int st ,int dr)
{int h=val%p;
nod *q=new nod;
q->inf=val;q->x=st;q->y=dr;q->urm=hash[h];
hash[h]=q;}
int main()
{int c,l,a[1025],s;
ifstream in("oite.in");
ofstream out("oite.out");
in>>c>>l;
for(int i=1;i<=c;i++)
in>>a[i];
for(int i=1;i<c;i++)
for(int j=i+1;j<=c;j++)
{s=a[i]+a[j];
add(s,i,j);
}
int contor=0;
for(int i=1;i<c;i++)
for(int j=i+1;j<=c;j++)
{s=l-a[i]-a[j];
int h=s%p;
for(nod *hh=hash[h];hh;hh=hh->urm)
if(hh->inf==s && i!=hh->x && i!=hh->y && j!=hh->x && j!=hh->y) {/*out<<a[i]+a[j]<<" "<<hh->inf<<" "<<hh->x<<" "<<hh->y<<" "<<i<<" "<<j<<" "<<'\n';*/contor++;}
}
out<<contor/6;
return 0;}