Pagini recente » Cod sursa (job #532514) | Cod sursa (job #1824791) | Cod sursa (job #2039137) | Cod sursa (job #2450456) | Cod sursa (job #595750)
Cod sursa(job #595750)
#include <cstdio>
#include <vector>
using namespace std;
struct sp
{
int s1,s2,s;
};
vector <sp> h[20001];
int v[1025];
inline bool comp(int i,int j,int k,int l)
{
if (h[i][j].s1==h[k][l].s1) return 0;
else if (h[i][j].s1==h[k][l].s2) return 0;
else if (h[i][j].s2==h[k][l].s1) return 0;
else if (h[i][j].s2==h[k][l].s2) return 0;
else return 1;
}
int main()
{
int i,j,k,l,a,aux,aux2,n,sol=0;
char ch[12000];
sp auxstr;
freopen("oite.in","r",stdin);
freopen("oite.out","w",stdout);
scanf("%d %d\n",&n,&l);
fgets(ch,11990,stdin);
for (i=1,j=-1;i<=n;++i)
{
++j;
while (ch[j]>='0'&&ch[j]<='9')
{
v[i]=v[i]*10+ch[j]-'0';
++j;
}
}
for (i=1;i<n;++i)
for (j=i+1;j<=n;++j)
{
auxstr.s1=i;
auxstr.s2=j;
auxstr.s=v[i]+v[j];
h[auxstr.s%20001].push_back(auxstr);
}
for (i=0;i<20001;++i)
{
aux=h[i].size();
a=(l-i)%20001;
if (a<0) a+=20001;
aux2=h[a].size();
for (j=0;j<aux;++j)
for (k=0;k<aux2;++k)
if (h[i][j].s+h[a][k].s==l)
if (comp(i,j,a,k))
++sol;
}
printf("%d",sol/6);
return 0;
}