Cod sursa(job #1226883)

Utilizator ArmandNMArmand Nicolicioiu ArmandNM Data 9 septembrie 2014 00:19:15
Problema Oite Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <fstream>
#include <vector>

const int NMAX = 1030;
const int MOD = 8000;

using namespace std;
ifstream f("oite.in");
ofstream g("oite.out");

int N,key;
long long sol,a[NMAX],x,aux,L;
vector <long long> Hash[MOD+5];

int main()
{
    f >> N >> L;
    for (int i = 1; i <= N; ++i)
    {
        f >> x;
        if (x < L)
        {
            a[++a[0]] = x;
        }
    }
    N = a[0];

    for (int i = 1; i <= N; ++i)
    {
        for (int j = i+1; j <= N; ++j)
        {
            aux = L - a[i] - a[j];
            if (aux < 0)
                continue;
            key = aux % MOD;
            for (int k = 0; k < Hash[key].size(); ++k)
            {
                if (Hash[key][k] == aux)
                    sol++;
            }
        }
        for (int j = 1; j < i; ++j)
        {
            aux = a[i] + a[j];
            key = aux % MOD;
            Hash[key].push_back(aux);
        }
    }

    g << sol;

    f.close();
    g.close();
    return 0;
}