Cod sursa(job #3361478)

Utilizator CorvinJudge0Corvin Judge CorvinJudge0 Data 24 iulie 2026 17:02:06
Problema Patrate 3 Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.14 kb
#include <bits/stdc++.h>

using namespace std;

const int LIM = 1e3, INM = 1e6;
const long long int BINM = 1e10, INF = 1e18 + 67;


ifstream fin ("patrate3.in");
ofstream fout ("patrate3.out");

struct coords {
    long long int x, y;
    bool operator<(const coords& other) const {
        if (x != other.x)
            return x < other.x;
        return y < other.y;
    }
};

struct segment {
    long long int panta, mx, my, len;
    bool operator<(const segment& other) const {
        if (panta != other.panta)
            return panta < other.panta;
        if (len != other.len)
            return len < other.len;
        if (mx < other.mx)
            return mx < other.mx;
        return my < other.my;
    }
};

map<segment, int> mp;
map<coords, int> test;
coords puncte[LIM + 9];
vector<segment> segmente;

int main() {
    int n;
    fin >> n;
    for (int i = 1; i <= n; i++) {
        double x, y;
        fin >> x >> y;
        puncte[i] = {int(x * INM), int(y * INM)};
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            int dx = abs(puncte[i].x - puncte[j].x);
            int dy = abs(puncte[i].y - puncte[j].y);

            int xs = puncte[i].x < puncte[j].x ? puncte[i].x : puncte[j].x;
            int ys = puncte[i].y < puncte[j].y ? puncte[i].y : puncte[j].y;

            segment s;
            s.mx = dx / 2 + xs;
            s.my = dy / 2 + ys;
            if (dx == 0)
                s.panta = INF;
            else
                s.panta = dy * INM / dx;
            s.len = (1ll * dx * dx) + (1ll * dy * dy);
            if (test.count({s.mx, s.my})) {
                //cout << "!";
            }
            test[{s.mx, s.my}]++;

            //cout << s.mx << ' ' << s.my << ' ' << s.panta << ' ' << s.len << endl;

            long long int otherpanta = INF;
            if (dy != 0) {
                otherpanta = dx * INM / dy;
            }

            if (mp.count({otherpanta, s.mx, s.my, s.len})) {
                ans += mp[{otherpanta, s.mx, s.my, s.len}];
            }

            segmente.push_back(s);
            mp[s] += 1;
        }
    }

    fout << ans;

    return 0;
}