Cod sursa(job #2636775)

Utilizator loraclorac lorac lorac Data 19 iulie 2020 20:51:58
Problema Trapez Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in("trapez.in");
ofstream out("trapez.out");
typedef long long ll;
#define x first
#define y second
pair<ll,ll> p[1005];
unordered_map<ll,ll> ump;
const ll A=4999999799;
const ll B=4999999937;
int main()
{
    ll n;
    in>>n;
    for(ll i=1;i<=n;++i)
        in>>p[i].x>>p[i].y;
    ll ans=0;
    for(ll i=1;i<=n-1;++i)
    for(ll j=i+1;j<=n;++j)
    {
        ll x=p[i].x;
        ll y=p[i].y;
        ll xx=p[j].x;
        ll yy=p[j].y;
        if(x>xx)
        {
            swap(x,xx);
            swap(y,yy);
        }
        ll d=__gcd(xx-x,abs(yy-y));
        ll dx=(xx-x)/d;
        ll dy=(yy-y)/d+2e9;
        ll h=(dx*A+dy)%B;
        ans+=(ump[h]++);
    }
    out<<ans<<'\n';
    return 0;
}