Cod sursa(job #3148620)

Utilizator andiRTanasescu Andrei-Rares andiR Data 2 septembrie 2023 20:58:06
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.3 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <iomanip>
#include <vector>

#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front

using namespace std;
ifstream fin ("trapez.in");
ofstream fout ("trapez.out");
typedef long long ll;
const ll Nmax=1e3, inf=2e9+5;
using pll=pair<ll, ll>;
struct point{
    ll x, y;
};

int n;
point v[Nmax];
unordered_map <ll, int> pant;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    fin>>n;
    for (int i=0; i<n; i++)
        fin>>v[i].x>>v[i].y;
    for (int i=0; i<n; i++)
        for (int j=i+1; j<n; j++){
            ll a=v[i].y-v[j].y, b=v[i].x-v[j].x;
            if (a==0)
                pant[inf]++;
            else if (b==0)
                pant[1]++;
            else{
                ll gcd=__gcd(abs(a), abs(b));
                ll sgn;
                if (a*b>0)
                    sgn=1;
                else sgn=-1;
                pant[(abs(a)/gcd*inf+abs(b)/gcd)*sgn]++;
            }
        }
    ll sol=0;
    for (auto it:pant)
        sol+=it.second*(it.second-1)/2;
    fout<<sol;
    return 0;
}