Cod sursa(job #1741770)

Utilizator fanache99Constantin-Buliga Stefan fanache99 Data 15 august 2016 00:59:08
Problema Oite Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <fstream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <queue>
#include <cstring>
#include <algorithm>
#include <queue>
#include <unordered_set>
#include <set>
#include <map>
#include <stack>
using namespace std;

ifstream cin("oite.in");
ofstream cout("oite.out");

const int MOD = 10007;
const int MAXN = 1024;

int v[1 + MAXN];
vector<pair<int, int> > table[MOD];

void Add(int value) {
    int which = value % MOD;
    for (auto &it : table[which])
        if (it.first == value) {
            it.second++;
            return;
        }
    table[which].push_back(make_pair(value, 1));
}

int Find(int value) {
    int which = value % MOD;
    for (auto &it : table[which])
        if (it.first == value)
            return it.second;
    return 0;
}

int main() {
    int c, l;
    long long answer = 0;
    cin >> c >> l;
    for (int i = 1; i <= c; i++)
        cin >> v[i];
    for (int i = 1; i < c; i++) {
        for (int j = i + 1; j <= c; j++)
            if (l - v[i] - v[j] >= 0)
                answer += Find(l - v[i] - v[j]);
        for (int j = 1; j < i; j++)
            Add(v[i] + v[j]);
    }
    cout << answer;
    return 0;
}