Cod sursa(job #1605940)

Utilizator LuurAndrei Florea Luur Data 19 februarie 2016 17:07:27
Problema Oite Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <fstream>
#include <vector>
#include <algorithm>
#define Hmax 1572869
#define Tmax 1025
using namespace std;
ifstream in("oite.in");
ofstream out("oite.out");
typedef long ll;
vector<ll> v[Hmax];
int N;
ll a[Tmax];
long long L, R = 0;
ll h(ll x){
    return x % Hmax;
}
void Find(ll x){
    ll n = h(x);
    for(vector<ll>::iterator 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];
    }
    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++){
            ll s = a[i] + a[k];
            if(s <= L ){
               ll x = h(s);
               v[x].push_back(s);
            }
        }
    }
    out<<R<<'\n';
    return 0;
}