Cod sursa(job #1500013)

Utilizator eu3neuomManghiuc Teodor-Florin eu3neuom Data 11 octombrie 2015 14:01:21
Problema Oite Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <bits/stdc++.h>

using namespace std;

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

const int MOD = 6007;
const int NMax = 1030;

int v[NMax];

vector < int > Hash[MOD];

int main(){
    int n, l, value, line, answer = 0;
    vector < int > ::iterator it;
    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++){
            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) answer++;
                }
            }
        }
        for(int j = 1; j < i; j++){
            value = v[i] + v[j];
            Hash[value % MOD].push_back(value);
        }
    }
    fout << answer;
    return 0;
}