Cod sursa(job #543408)

Utilizator Magnuscont cu nume gresit sau fals Magnus Data 27 februarie 2011 23:19:21
Problema Oite Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <stdio.h>
#include <vector>

using namespace std;

struct sp
{
    int s1,s2,s;
};

vector <sp> h[15013];
sp aux;
int n,v[1025],sol;

inline bool comp(int i,int j,int k,int l)
{
    if (h[i][j].s1==h[k][l].s1) return 0;
    if (h[i][j].s1==h[k][l].s2) return 0;
    if (h[i][j].s2==h[k][l].s1) return 0;
    if (h[i][j].s2==h[k][l].s2) return 0;
    return 1;
}

int main()
{
    int i,j,k,l,a;
    freopen("oite.in","r",stdin);
    freopen("oite.out","w",stdout);
    scanf("%d%d",&n,&l);
    for (i=1;i<=n;++i)
        scanf("%d",&v[i]);
    for (i=1;i<=n;++i)
        for (j=i+1;j<=n;++j)
            if (i!=j)
            {
                aux.s1=i;
                aux.s2=j;
                aux.s=v[i]+v[j];
                h[aux.s%15013].push_back(aux);
            }
    for (i=0;i<=15013;++i)
        for (j=0;j<h[i].size();++j)
        {
            a=(l-i)%15013;
            if (a<0) a+=15013;
            for (k=0;k<h[a].size();++k)
                if ((h[i][j].s+h[a][k].s==l)&&(comp(i,j,a,k)))
                    ++sol;
        }
    printf("%d",sol/6);
    return 0;
}