Pagini recente » Cod sursa (job #665549) | Cod sursa (job #1841456) | Cod sursa (job #2060485) | Cod sursa (job #528189) | Cod sursa (job #539678)
Cod sursa(job #539678)
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
int n,i,j,k,v[1100],l,pos,ok,coun;
struct oite
{
int val,i,j;
};
const int maxp=666013;
vector<oite> h[maxp];
oite t;
int main()
{
freopen("oite.in","r",stdin);
freopen("oite.out","w",stdout);
scanf("%d%d",&n,&l);
for(i=1;i<=n;i++)
scanf("%d",&v[i]);
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
{
t.val=(v[i]+v[j]);
t.i=i;
t.j=j;
h[(v[i]+v[j])%maxp].push_back(t);
}
for(i=0;i<min(l,maxp);i++)
{
if(h[i].size()>0)
{
for(j=0;j<h[i].size();j++)
{
for(k=0;k<h[(l-h[i][j].val)%maxp].size();k++)
{
if(h[i][j].i!=h[(l-h[i][j].val)%maxp][k].i&&h[i][j].j!=h[(l-h[i][j].val)%maxp][k].j&&h[i][j].i!=h[(l-h[i][j].val)%maxp][k].j&&h[i][j].j!=h[(l-h[i][j].val)%maxp][k].i&&h[(l-h[i][j].val)%maxp][k].val+h[i][j].val==l&&h[i][j].j<h[(l-h[i][j].val)%maxp][k].i)
coun++;
}
}
}
}
printf("%d",coun);
return 0;
}