Cod sursa(job #2514260)

Utilizator PopescuAndreiAlexandruPopescu Andrei Alexandru PopescuAndreiAlexandru Data 24 decembrie 2019 23:13:16
Problema Oite Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.27 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

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

#define MOD 100021
#define x first
#define y second
#define ll long long

vector < pair<int,int> > Hash[MOD];

ll n,v[1050],l;

ll ans=0;

void Read()
{
    fin>>n>>l;
    for(int i=1;i<=n;i++)
        fin>>v[i];
}

void Push_Hash(int value)
{
    int List=value%MOD,ok=0;
    vector < pair<int,int> > ::iterator it;
    for(it=Hash[List].begin();it!=Hash[List].end();it++)
    {
        if((*it).x==value)
        {
            (*it).y++;
            return;
        }
    }
    Hash[List].push_back(make_pair(value,1));
}

int Find_Hash(int value)
{
    int List=value%MOD;
    vector < pair<int,int> > ::iterator it;
    for(it=Hash[List].begin();it!=Hash[List].end();it++)
    {
        if((*it).x==value)
            return (*it).y;
    }
    return 0;
}

void Sol()
{
    for(int i=1;i<n;i++)
    {
        for(int j=i+1;j<=n;j++)
            ans+=Find_Hash(l-(v[i]+v[j]));
        for(int j=i-1;j>=1;j--)
        {
            if((v[i]+v[j])<=l)
                Push_Hash(v[i]+v[j]);
        }
    }
    fout<<ans<<'\n';
}

int main()
{
    Read();
    Sol();
}