Cod sursa(job #1582702)

Utilizator pepsiM4A1Ozturk Arif pepsiM4A1 Data 28 ianuarie 2016 12:23:44
Problema Oite Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <cstdio>
#include <vector>
#define CMAX 10000
#define MOD 666013
using namespace std;
vector<int>h[MOD+10];
int c,l;
int v[CMAX];
void addtohash(int x)
{
    h[x%MOD].push_back(x);
}
int findit(int x)
{
    if(x<0) return 0;
    int ct=0;
    int key=x%MOD;
    vector<int>::iterator it;
    for(it=h[key].begin();it!=h[key].end();++it)
    {
        if(*it==x) ++ct;
    }
    return ct;
}
int main()
{
    freopen ("oite.in","r",stdin);
    freopen ("oite.out","w",stdout);
    scanf("%d%d",&c,&l);
    long long ct=0;
    for(int i=1;i<=c;i++)
    {
        scanf("%d",&v[i]);
    }
    for(int i=1;i<c;i++)
    {
        for(int j=i+1;j<=c;j++)
        {
            ct+=findit(l-v[i]-v[j]);
        }
        for(int j=1;j<i;j++)
        {
            addtohash(v[i]+v[j]);
        }
    }
    printf("%lld\n",ct);
}