Cod sursa(job #1770262)

Utilizator giotoPopescu Ioan gioto Data 3 octombrie 2016 22:38:06
Problema Oite Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include <cstdio>
#include <vector>
#define MOD 32767
using namespace std;

int x, n, L, a[1026];
long long Sol = 0;
vector<int> Hash[MOD + 1];
inline void SolveHash(int x){
    int List = x % MOD;
    vector<int>::iterator it;
    for(it = Hash[List].begin(); it != Hash[List].end(); ++it)
        if(*it == x)
            ++Sol;
    return ;
}
int main()
{
    freopen("oite.in", "r", stdin);
    freopen("oite.out", "w", stdout);
    scanf("%d%d", &n, &L);
    int NR = 0;
    for(int i = 1; i <= n; ++i){
        scanf("%d", &x);
        if(x > L)
            continue ;
        a[++NR] = x;
    }
    for(int i = 1; i <= NR; ++i){
        for(int j = i + 1; j <= NR; ++j){
            int S = L - a[i] - a[j];
            if(S < 0) continue ;
            SolveHash(S);
        }
        for(int j = 1; j < i; ++j){
            int S = a[i] + a[j];
            int List = S % MOD;
            Hash[List].push_back(S);
        }
    }
    printf("%d", Sol);
    return 0;
}