Cod sursa(job #799003)

Utilizator Mihai22eMihai Ionut Enache Mihai22e Data 17 octombrie 2012 18:46:56
Problema Oite Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
#include<stdio.h>
#include<fstream>
#include<vector>

using namespace std;

#define MOD 666013
#define MAXN 1030

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

int n, i, j;
int a[ MAXN ];
long long int L, res;

inline void insert_value_v(int x)
{
    int l = x % MOD;
    int ii;

    for(ii = 0; ii < v[l].size(); ++ii)
        if(v[l][ii].first == x)
            {
                ++v[l][ii].second;
                return;
            }

    v[l].push_back(make_pair(x, 1));
}

inline int search_value_v(int x)
{
    int l = x % MOD;
    int ii;

    for(ii = 0; ii < v[l].size(); ++ii)
        if(v[l][ii].first == x)
            return v[l][ii].second;

    return 0;
}

int main()
{
    ifstream f("oite.in");

    f >> n >> L;
    for(i = 1; i <= n; ++i)
        f >> a[i];


    f.close();

    FILE *g = fopen("oite.out", "w");

    for(i = 1; i < n; ++i)
    {
        for(j = i + 1; j <= n; ++j)
        {
            if(L - a[i] - a[j] >= 0)
                    res += search_value_v(L - a[i] - a[j]);
        }

        for(j = 1; j < i; ++j)
            insert_value_v(a[i] + a[j]);
    }

    fprintf(g, "%lld\n", res);

    fclose(g);

    return 0;
}