Mai intai trebuie sa te autentifici.

Cod sursa(job #1604545)

Utilizator LuurAndrei Florea Luur Data 18 februarie 2016 13:18:01
Problema Loto Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.54 kb
#include <fstream>
#include <vector>
#include <algorithm>
#define Hmax 393241
#define Tmax 101
using namespace std;
ifstream in("loto.in");
ofstream out("loto.out");
typedef long ll;
struct myType{
    int a, b, c;
    ll s;
};
vector <myType> v[Hmax];
ll N, S, a[Tmax];
bool t = 1;
ll h(ll x){
    return x % Hmax;
}
myType Find(ll x){
   ll n = h(x), i, sz = v[n].size();
   bool _t = 0;
   myType T;
   for(i = 0; i < sz && !_t; i++){
        T = v[n][i];
        if (T.s == x) _t = 1;
   }
   if (!_t) T.s = -1;
   return T;
}
int main(){
    in>>N>>S;
    for(int i = 1; i <= N; i++){
        in >> a[i];
    }
    for(int i = 1; i <= N; i++){
        for(int j = i; j <= N; j++){
            for(int k = j; k <= N; k++){
                ll s = a[i]+a[j]+a[k];
                if (s <= S){
                    ll m = h(s);
                    myType T;
                    T.a = a[i]; T.b = a[j]; T.c = a[k]; T.s = s;
                    v[m].push_back(T);
                }
            }
        }
    }
    for(int i = 1; i <= N && t; i++){
        for(int j = i; j <= N && t; j++){
            for(int k = j; k <= N && t; k++){
                ll s = a[i] + a[j] + a[k];
                if (S - s >= 0){
                    myType f = Find(S - s);
                    if (f.s != -1){ t = 0;
                        out << a[i] <<' '<< a[j] <<' '<< a[k] <<' '<< f.a <<' '<< f.b <<' '<< f.c<<'\n';
                    }
                }
            }
        }
    }
    if(t) out <<-1<<'\n';
    return 0;
}