Cod sursa(job #2935634)

Utilizator matthriscuMatt . matthriscu Data 7 noiembrie 2022 10:42:31
Problema Trapez Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <bits/stdc++.h>
using namespace std;

#define NMAX 1005

#define merge(x, y) (((x) << 32LL) | (y))
#define first(x) ((x) >> 32LL)
#define second(x) ((x) & UINT_MAX)

typedef long long ll;

ll slope(ll a, ll b) {
	ll dy = second(a) - second(b), dx = first(a) - first(b);

	if (dx == 0)
		return merge(0LL, 1LL);
	if (dy == 0)
		return merge(1LL, 0LL);

	if ((dx < 0) + (dy < 0) == 1)
		dy = -abs(dy);
	else
		dy = abs(dy);

	dx = abs(dx);

	ll gcd = __gcd(dx, dy);

	return merge(dx / gcd, dy / gcd);
}

int main() {
	ifstream fin("trapez.in");
	ofstream fout("trapez.out");

	int n;
	fin >> n;

	vector<ll> points(n);
	for (ll i = 0, x, y; i < n; ++i) {
		fin >> x >> y;
		points[i] = merge(x, y);
	}

	unordered_map<ll, int> m;
	for (int i = 0; i < n; ++i)
		for (int j = i + 1; j < n; ++j)
			++m[slope(points[i], points[j])];

	int ans = 0;
	for(auto& [_, i] : m)
		ans += (i * (i - 1)) / 2;

	fout << ans << '\n';
}