結果

問題 No.2769 Number of Rhombi
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2024-05-08 19:16:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,444 bytes
コンパイル時間 2,503 ms
コンパイル使用メモリ 216,908 KB
実行使用メモリ 46,336 KB
最終ジャッジ日時 2024-05-08 19:16:17
合計ジャッジ時間 4,127 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 WA -
testcase_03 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

//fraction (p/q)
struct fraction{
    int p, q;
    fraction(int P=0, int Q=1) : p(P), q(Q) {
        int g = gcd(P, Q);
        p /= g; q /= g;
        if (q < 0){
            p *= -1;
            q *= -1;
        }
        if (q == 0) p = 1;
        if (p == 0) q = 1;
    }
    bool operator < (const fraction & other) const{
        if (p < 0) return -p*other.q > -other.p*q;
        return p*other.q < other.p*q;
    }
    bool operator == (const fraction & other) const{
        return p*other.q == other.p*q;
    }
    bool operator > (const fraction & other) const{
        if (p < 0) return -p*other.q < -other.p*q;
        return p*other.q > other.p*q;
    }
};


int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int N, ans=0;
    cin >> N;
    vector<int> x(N), y(N);
    for (int i=0; i<N; i++) cin >> x[i] >> y[i];
    
    map<tuple<int, int, fraction>, int> mp;
    for (int i=0; i<N; i++){
        for (int j=i+1; j<N; j++){
            fraction p(y[i]-y[j], x[i]-x[j]);
            mp[{x[i]+x[j], y[i]+y[j], p}]++;
        }
    }

    for (auto &[a, b] : mp){
        fraction p, q;
        int xx, yy;
        tie(xx, yy, p) = a;
        q = fraction(-p.q, p.p);
        ans += mp[{xx, yy, q}] * b;
        if (mp[{xx, yy, q}] * b > 100){
            cout << mp[{xx, yy, q}] * b << endl;
        }
    }

    cout << ans/2 << endl;

    return 0;
}
0