Cod sursa(job #1777358)

Utilizator savulescustefanSavulescu Stefan savulescustefan Data 12 octombrie 2016 12:16:08
Problema Oite Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.31 kb
#include <cstdio>
#include <vector>
using namespace std;
vector <int> v[666017],v1[666017];
vector <int>::iterator it;
int i,j,k,z,x,x1,l,n,a[1028];
long long nr;
bool ok;
int main()
{
    freopen ("oite.in","r",stdin);
    freopen ("oite.out","w",stdout);
    scanf ("%d %d", &n, &l);
    a[0]=-1;
    for (i=1;i<=n;i++)
        scanf ("%d", &a[i]);
    for (i=(n-2);i>=2;i--)
    {
        for (j=(i+2);j<=n;j++)
        {
            x=a[i+1]+a[j];
            x1=x%666013;
            ok=false;
            for (it=v[x1].begin();it<v[x1].end();it++)
            {
                if (*it==x)
                {
                    ok=true;
                    v1[x1][k]++;
                    break;
                }
            }
            if (ok==false)
            {
                v[x1].push_back(x1);
                v1[x1].push_back(1);
            }
        }
        for (j=1;j<i;j++)
        {
            x=l-a[i]-a[j];
            if (x>=0)
            {
            x1=x%666013;
            for (it=v[x1].begin();it<v[x1].end();it++)
            {
                if (*it==x)
                {
                    nr=0LL+nr+v1[x1][k];
                    break;
                }
            }
            }
        }
    }
    printf ("%lld", nr);
    return 0;
}