Cod sursa(job #1605954)

Utilizator LuurAndrei Florea Luur Data 19 februarie 2016 17:22:47
Problema Oite Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <fstream>
#include <vector>
#include <algorithm>
#define Hmax 393241
#define Tmax 1030
using namespace std;
ifstream in("oite.in");
ofstream out("oite.out");
typedef long ll;
typedef vector<ll>::iterator vl_i;
vector<ll> v[Hmax];
int N;
ll a[Tmax];
long long L, R = 0;
inline ll h(ll x){
    return x % Hmax;
}
void Find(ll x){
    ll n = h(x);
    for(vl_i i = v[n].begin(); i != v[n].end(); i++){
        if ((*i) == x) R++;
    }
}
int main(){
    in>>N>>L;
    for(int i = 1; i <= N; i++){
        in>>a[i];
    }
    sort(a+1,a+N+1);
    for(int i = 1; i <= N; i++){
        for(int j = i+1; j <= N; j++){
                ll s = L - a[i] - a[j];
                if(s >= 0 ){
                  Find(s);
                }
        }
        for(int k = 1; k < i; k++){
            long long s = a[i] + a[k];
            if(s <= L ){
               ll x = h(s);
               v[x].push_back(s);
            }
        }
    }
    out<<R<<'\n';
    return 0;
}