Cod sursa(job #220323)

Utilizator AthanaricCirith Gorgor Athanaric Data 10 noiembrie 2008 14:43:42
Problema Triplete Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <stdio.h>
#define N 4300
int n,m,a[N][N/32+1];
int minim (int a, int b)
{
	if (a>b)
		return b;
	return a;
}
void citirith()
{
	int x,y,s;
	scanf("%d%d",&n,&m);
	for (int i=1; i<=m; i++)
	{
		scanf("%d%d",&x,&y);
		s=x+y;
		x=minim(x,y); y=s-x;
		a[x][y>>5]|=1<<(y&31);
	}
}
void rezolvarith()
{
	int 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/=2;
				}
				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;
}