Cod sursa(job #2285850)

Utilizator Bulboaca_EugenBulboaca Alexandru Eugen Bulboaca_Eugen Data 19 noiembrie 2018 13:29:26
Problema Oite Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("oite.in");
ofstream fout("oite.out");
#define MAXP 100007
int v[1025], cnt;
vector <int> hashh[100010];
void insertt(int s){
    int modulo = s % MAXP;
    hashh[modulo].push_back(s);
}
int query(int s){
    int modulo = s % MAXP, contor = 0;
    for(int i = 0; i < hashh[modulo].size(); ++i){
        if(hashh[modulo][i] == s)
            contor ++;
    }
    return contor ;
}
int main()
{
    int n, S;
    fin >> n >> S;
    for(int i = 1; i <= n; ++i)
        fin >> v[i];
    sort(v + 1, v + n + 1);
    for(int i = 1; i < n; i++){
        for(int j = i + 1; j <= n; j++){
            int suma = v[i] + v[j];
            if (suma > S) continue;
            cnt += query(S - suma);
        }
        for(int j = 1; j < i; ++j){
            insertt(v[i] + v[j]);
        }
    }
    fout << cnt ;
    return 0;
}
//int n, m , matrix [201][201], dp[201][201];