Pagini recente » Borderou de evaluare (job #2096634) | Cod sursa (job #2179833) | Cod sursa (job #3356148) | Cod sursa (job #3355703) | Cod sursa (job #1581902)
#include <cstdio>
#include <vector>
#define CMAX 1024
#define MOD 666013
using namespace std;
struct str
{
int o1;
int o2;
int cost;
};
vector<str>h[MOD];
int c,l;
int v[CMAX];
void addtohash(str x)
{
h[x.cost%MOD].push_back(x);
}
int egal(str a,str b)
{
if(a.cost==l-b.cost) return 0;
return 1;
}
int findit(str x)
{
int ct=0;
int key=(l-x.cost)%MOD;
vector<str>::iterator it;
for(it=h[key].begin();it!=h[key].end();++it)
{
if((egal(*it,x)==0)) ++ct;
}
return ct;
}
int main()
{
freopen ("oite.in","r",stdin);
freopen ("oite.out","w",stdout);
scanf("%d%d",&c,&l);
long long ct=0;
for(int i=1;i<=c;i++)
{
scanf("%d",&v[i]);
}
for(int i=1;i<=c;i++)
{
for(int j=i+1;j<=c;j++)
{
str x;
x.o1=i;
x.o2=j;
x.cost=v[i]+v[j];
ct+=findit(x);
}
for(int j=1;j<i;j++)
{
str x;
x.o1=i;
x.o2=j;
x.cost=v[i]+v[j];
addtohash(x);
}
}
printf("%lld\n",ct);
}