Cod sursa(job #1581905)

Utilizator pepsiM4A1Ozturk Arif pepsiM4A1 Data 27 ianuarie 2016 12:22:18
Problema Oite Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <cstdio>
#include <vector>
#define CMAX 2955
#define MOD 6013
using namespace std;
vector<int>h[MOD];
int c,l;
int v[CMAX];
void addtohash(int x)
{
    h[x%MOD].push_back(x);
}
int findit(int x)
{
    int ct=0;
    int key=(l-x)%MOD;
    vector<int>::iterator it;
    for(it=h[key].begin();it!=h[key].end();++it)
    {
        if(*it==l-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(v[i]+v[j]);
        }
        for(int j=1;j<i;j++)
        {
            addtohash(v[i]+v[j]);
        }
    }
    printf("%lld\n",ct);
}