結果

問題 No.2769 Number of Rhombi
ユーザー Today03
提出日時 2024-05-31 22:33:20
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 1,344 bytes
コンパイル時間 2,553 ms
コンパイル使用メモリ 216,392 KB
最終ジャッジ日時 2025-02-21 18:09:11
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15 MLE * 3 -- * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9 + 10;
const ll INFL = 4e18;

int main() {
    int N;
    cin >> N;
    vector<pair<ll, ll>> XY(N);
    for (int i = 0; i < N; i++) {
        cin >> XY[i].first >> XY[i].second;
    }

    map<ll, vector<vector<ll>>> mp;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            ll dx = XY[j].first - XY[i].first;
            ll dy = XY[j].second - XY[i].second;
            ll d = dx * dx + dy * dy;
            if (mp.count(d) == 0) {
                mp[d].resize(N);
            }
            mp[d][i].push_back(j);
            mp[d][j].push_back(i);
        }
    }

    ll ans = 0;
    for (auto [k, G] : mp) {
        for (int i = 0; i < N; i++) {
            if (G[i].size() < 2) continue;
            queue<tuple<int, int, int>> Q;
            Q.push({i, 0, -1});
            while (!Q.empty()) {
                auto [now, c, pre] = Q.front();
                Q.pop();
                for (auto nxt : G[now]) {
                    if (nxt == pre) continue;
                    if (c == 3) {
                        if (nxt == i) ans++;
                        continue;
                    }
                    Q.push({nxt, c + 1, now});
                }
            }
        }
    }

    cout << ans / 8 << endl;
}
0