Cod sursa(job #1797042)

Utilizator CiurezAndreiCiurez Marius-Andrei CiurezAndrei Data 3 noiembrie 2016 22:51:21
Problema Oite Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.13 kb
#include <bits/stdc++.h>

#define key 66017

using namespace std;

ifstream fin("oite.in");
ofstream fout("oite.out");

int solution;
int v[2048], N, L;
vector< pair<int, int> >H[66018];

inline int hashFind(const int &x)
{
    int cheie = x % key;

    for(auto it : H[cheie])
    {
        if(it.second == x)
        {
            return it.first;
        }
    }
    return 0;
}

inline void hashInsert(const int &x)
{
    int cheie = x % key;
    for(auto it : H[cheie])
    {
        if(it.second == x)
        {
            it.first ++;
            return;
        }
    }
    H[cheie].push_back(make_pair(1, x));
}

int main()
{
    fin >> N >> L;

    for(int i = 1; i <= N; i ++)
    {
        fin >> v[i];
    }

    for(int i = 1; i < N; i ++)
    {
        for(int j = i + 1; j <= N; j ++)
        {
            if(  L - v[i] - v[j] > 0)
            {
                solution  += hashFind(L - v[i] - v[j]);
            }
        }
        for(int j = 1; j < i; j ++)
        {
            hashInsert(v[i] + v[j]);
        }
    }

    fout << solution;

    return 0;
}