Cod sursa(job #220316)

Utilizator AthanaricCirith Gorgor Athanaric Data 10 noiembrie 2008 14:36:23
Problema Triplete Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.84 kb
#include <stdio.h>
#define N 4300
long long n,m,a[N][N/32];
int minim (int a, int b)
{
	if (a>b)
		return b;
	return a;
}
void citirith()
{
	long long x,y,s;
	scanf("%lld%lld",&n,&m);
	for (int i=1; i<=m; i++)
	{
		scanf("%lld%lld",&x,&y);
		s=x+y;
		x=minim(x,y); y=s-x;
		a[x][y>>5]|=1<<(y&31);
	}
}
void rezolvarith()
{
	long long sol,z,cat,check,xz0r;
	long long solmax=0;
	for (int i=1; i<n; i++)
		for (int j=i+1; j<=n; j++)
		{
			
			check=j/32;
			if (!(a[i][check] & (1<<(j&31))))
				continue;
			sol=0;
			for (int k=1; k<=n/32+1; k++)
			{
				z=a[i][k]&a[j][k];
				cat=0;
				/*while (z)
				{
					if (z%2)
						++cat;
					z&=z-1;
				}
				sol+=cat;*/
			}
			solmax+=(long long)sol;
		}
	printf("%lld\n",solmax);
}
int main()
{
	freopen("triplete.in","r",stdin);
	freopen("triplete.out","w",stdout);
	citirith();
	rezolvarith();
	return 0;
}