Cod sursa(job #32200)

Utilizator azotlichidAdrian Vladu azotlichid Data 17 martie 2007 14:40:01
Problema Oite Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
using namespace std;

#define FORI(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); ++it)
#define FOR(i, N, M) for (int i = (int)(N); i <= (int)(M); ++i)
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)

#define PMAX 666013
vector<pair<int, int> > h[PMAX];

typedef long long LL;

int N, L, a[1024];

int get(int x)
{
    if (x < 0) return 0;
    int t = x % PMAX;
    FORI(it, h[t])
        if (it->first == x)
            return it->second;
    return 0;
}

void inc(int x)
{
    int t = x % PMAX;
    FORI(it, h[t])
        if (it->first == x) { ++ it->second; return; }
    h[t].push_back(make_pair(x, 1));
}

int main(void)
{
    freopen("oite.in", "r", stdin);
    freopen("oite.out", "w", stdout);
    scanf("%d %d", &N, &L);
    REP(i, N) scanf("%d", &a[i]);

    LL Ans = 0;
    REP(i, N)
    {
        FOR(j, i+1, N-1)
            Ans += get(L-a[i]-a[j]);
        FOR(j, 0, i-1)
            inc(a[i]+a[j]);
    }

    printf("%lld\n", Ans);
    return 0;
}