結果

問題 No.2769 Number of Rhombi
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2024-01-18 08:43:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,453 bytes
コンパイル時間 2,502 ms
コンパイル使用メモリ 218,192 KB
実行使用メモリ 34,816 KB
最終ジャッジ日時 2024-05-08 20:15:23
合計ジャッジ時間 19,739 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 267 ms
27,136 KB
testcase_04 AC 277 ms
25,344 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 567 ms
34,688 KB
testcase_23 AC 646 ms
34,688 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 568 ms
34,688 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 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 (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;
    }
    pair<int, int> top() const{
        return {p, q};
    }
};


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

    int N, ans=0, s, t, a, b, c, d;
    cin >> N;
    vector<int> x(N), y(N);
    for (int i=0; i<N; i++) cin >> x[i] >> y[i];
    
    map<tuple<int, int, int, int>, 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]);
            tie(s, t) = p.top();
            mp[{x[i]+x[j], y[i]+y[j], s, t}]++;
        }
    }

    for (auto &[g, h] : mp){
        tie(a, b, c, d) = g;
        fraction q = fraction(-d, c);
        tie(s, t) = q.top();
        if(mp.count({a, b, s, t})) ans += mp[{a, b, s, t}] * h;
    }

    cout << ans/2 << endl;

    return 0;
}
0