Cod sursa(job #1180095)

Utilizator andrei_diaconuAndrei Diaconu andrei_diaconu Data 29 aprilie 2014 22:21:07
Problema Oite Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>
#include <vector>

#define modulo 666013
using namespace std;
ifstream f("oite.in");
ofstream g("oite.out");
vector<int> hasht[modulo];
int c, l, i, o[1025], j, posib;

void hasht_insert(int s)
{
    int list = s%modulo;
    hasht[list].push_back(s);
}

int hasht_find(int s)
{
    int list = s%modulo;
    int ap=0;
    for (vector<int>::iterator it=hasht[list]. begin(); it!=hasht[list].end(); it++)
        if (*it == s)
            ap++;
    return ap;
}

int main()
{
    f>>c>>l;
    for (i=1; i<=c; i++)
        f>>o[i];
    for (i=1; i<=c; i++){
        for (j=i+1; j<=c; j++)
            if (l-o[i]-o[j]>0)
                posib+=hasht_find(l-o[i]-o[j]);
        for (j=1; j<=i-1; j++)
            hasht_insert(o[i]+o[j]);
    }
    g<<posib;
    return 0;
}