Cod sursa(job #1998314)

Utilizator MihaelaCismaruMihaela Cismaru MihaelaCismaru Data 7 iulie 2017 13:56:18
Problema Oite Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.3 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[666014];
int main(){
    in >> n >> l;
    for( i = 1; i <= n; i ++ ){
        in >> oite[i];
    }
    sume[(oite[1] + oite[2] ) %666013].push_back( make_pair (1,2));
    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%666013].size(); k ++ ){
                if( oite[sume[csum%666013][k].first] + oite[sume[csum%666013][k].second] == csum ){
                    grupuri_de_oite++;
                }
            }

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