Cod sursa(job #1998366)

Utilizator MihaelaCismaruMihaela Cismaru MihaelaCismaru Data 7 iulie 2017 16:24:45
Problema Oite Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.5 kb
#include<fstream>
#include<vector>
using namespace std;
ifstream in("oite.in");
ofstream out("oite.out");
int n,l,st,dr,mid,k,i,j,oite[1025],csum,alfa,beta,grupuri_de_oite,ok;
vector<pair<int,int> >sume[100009];
vector<int>nr[100009];
int main(){
    in >> n >> l;
    for( i = 1; i <= n; i ++ ){
        in >> oite[i];
    }
    sume[(oite[1] + oite[2] ) %100009].push_back( make_pair (1,2));
    nr[(oite[1] + oite[2] ) %100009 ].push_back(1);
    for( i = 3; i <= n-1; i ++ ){
        for( j = i+1; j <= n; j ++ ){
            csum = l -oite[i] - oite[j];
            for( k = 0; k < sume[csum%100009].size(); k ++ ){
                if( oite[sume[csum%100009][k].first] + oite[sume[csum%100009][k].second] == csum ){
                    grupuri_de_oite+= nr[csum%100009][k];
                }
            }

        }
        for( j = 1; j <= i-1; j ++ ){
            ok = 0;
            for( k = 0; k < sume[ ( oite[i] + oite[j] ) %100009 ].size(); k++ ){
                if( oite[sume[( oite[i] + oite[j] ) %100009][k].first] + oite[sume[( oite[i] + oite[j] ) %100009][k].second] == oite[i]+oite[j] ){
                    ok = 1;
                    nr[(oite[i] + oite[j] ) %100009][k]++;
                    break;
                }
            }
            if(ok == 0){
                sume[ ( oite[i] + oite[j] ) %100009 ].push_back( make_pair(i,j) );
                nr[(oite[i] + oite[j] ) %100009].push_back(1);
            }
        }
    }
    out<<grupuri_de_oite;
    return 0;
}