Cod sursa(job #340034)

Utilizator Bogdan_CCebere Bogdan Bogdan_C Data 12 august 2009 19:35:25
Problema Oite Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#include<fstream>
#define p 666013 
using namespace std;
struct nod{
       
       int inf;int x[1000],y[1000];
       nod *urm;};
nod *hash[666013];int length[666013];       
void add(int val,int st ,int dr)
{int h=val%p;
for(nod *hh=hash[h];hh;hh=hh->urm)
 {if(hh->inf==val) {length[val]++;int aux=length[val];hh->x[aux]=st;hh->y[aux]=dr;return ;}
        }
nod *q=new nod;
length[val]=1;int aux=1;
q->inf=val;
q->x[1]=st;
q->y[1]=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) {/*out<<a[i]+a[j]<<" "<<hh->inf<<" "<<hh->x<<" "<<hh->y<<" "<<i<<" "<<j<<" "<<'\n';*/
   for(int r=1;r<=length[s];r++)
    {if(i!=hh->x[r] && i!=hh->y[r] && j!=hh->x[r] && j!=hh->y[r]) contor++;}
   
   }
         }
         
    out<<contor/6; 
         
    return 0;}