Cod sursa(job #1226890)

Utilizator ArmandNMArmand Nicolicioiu ArmandNM Data 9 septembrie 2014 00:27:21
Problema Oite Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <fstream>
#include <vector>

const int NMAX = 1030;
const int MOD = 7919;

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

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

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

    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;
}