Cod sursa(job #1499995)

Utilizator eu3neuomManghiuc Teodor-Florin eu3neuom Data 11 octombrie 2015 13:39:44
Problema Oite Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.16 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("oite.in");
ofstream fout("oite.out");

const int MOD = 666013;
const int NMax = 1030;

struct Sheep{
    int value, a, b;
};

int v[NMax];

vector < Sheep > Hash[MOD];

int main(){
    int n, l, value, line;
    Sheep A;
    fin >> n >> l;
    for(int i = 1; i <= n; i++){
        fin >> v[i];
    }
    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            A.value = v[i] + v[j];
            A.a = i; A.b = j;
            Hash[A.value % MOD].push_back(A);
        }
    }
    vector < Sheep > ::iterator it;
    long long int answer = 0;
    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            value = l - (v[i] + v[j]);
            if(value >= 0){
                line = value % MOD;
                for(it = Hash[line].begin(); it != Hash[line].end(); it++){
                    if(it -> value == value && it -> a != i && it -> a != j && it -> b != i && it -> b != j){
                        answer++;
                    }
                }
            }
        }
    }
    fout << answer / 6;
    return 0;
}