Cod sursa(job #398158)

Utilizator Bogdan_CCebere Bogdan Bogdan_C Data 18 februarie 2010 01:38:19
Problema Oite Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.28 kb
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#define FIN "oite.in"
#define FOUT "oite.out"
#define p 666013
#define NMAX 5000000 

using namespace std;

int c,l,a[NMAX],s;

struct nod
       {       
       int inf,x,y;
       nod *urm;
       };
nod *hash[NMAX];       

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()
    {
          
          freopen(FIN,"r",stdin);
          freopen(FOUT,"w",stdout);
          scanf("%d %d\n",&c,&l);
          for(int i=1;i<=c;i++)
                  scanf("%d",&a[i]);
          sort(a+1,a+c+1);        
          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;
         if(hash[h]) 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*/) contor++;
         }
         
    printf("%d",contor/6); 
         
    return 0;}