Cod sursa(job #2975480)

Utilizator victor_gabrielVictor Tene victor_gabriel Data 6 februarie 2023 17:11:51
Problema Oite Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

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

const int DIM = 1025;
const int HASH_VALUE = 1000007;
vector<int> hashTable[HASH_VALUE];

int c, l, sol;
int nums[DIM];

int main() {
    fin >> c >> l;
    for (int i = 1; i <= c; i++)
        fin >> nums[i];

    int sum = nums[1] + nums[2];
    hashTable[sum % HASH_VALUE].push_back(sum);
    for (int i = 3; i < c; i++) {
        for (int j = i + 1; j <= c; j++) {
            int value = l - nums[i] - nums[j];
            if (value < 0) continue;

            int hash = value % HASH_VALUE;
            if (find(hashTable[hash].begin(), hashTable[hash].end(), value) != hashTable[hash].end())
                sol++;
        }

        for (int j = 1; j < i; j++) {
            int value = nums[j] + nums[i];
            int hash = value % HASH_VALUE;
            if (find(hashTable[hash].begin(), hashTable[hash].end(), value) == hashTable[hash].end())
                hashTable[hash].push_back(value);
        }
    }

    fout << sol;

    return 0;
}