Pagini recente » Cod sursa (job #1135216) | Sandbox (cutiuţa cu năsip) | Rating bosnea (slayer2k89) | Cod sursa (job #2025978) | Cod sursa (job #1797042)
#include <bits/stdc++.h>
#define key 66017
using namespace std;
ifstream fin("oite.in");
ofstream fout("oite.out");
int solution;
int v[2048], N, L;
vector< pair<int, int> >H[66018];
inline int hashFind(const int &x)
{
int cheie = x % key;
for(auto it : H[cheie])
{
if(it.second == x)
{
return it.first;
}
}
return 0;
}
inline void hashInsert(const int &x)
{
int cheie = x % key;
for(auto it : H[cheie])
{
if(it.second == x)
{
it.first ++;
return;
}
}
H[cheie].push_back(make_pair(1, x));
}
int main()
{
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 ++)
{
if( L - v[i] - v[j] > 0)
{
solution += hashFind(L - v[i] - v[j]);
}
}
for(int j = 1; j < i; j ++)
{
hashInsert(v[i] + v[j]);
}
}
fout << solution;
return 0;
}