結果
問題 | No.2769 Number of Rhombi |
ユーザー |
|
提出日時 | 2024-05-31 22:35:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 445 ms / 5,000 ms |
コード長 | 1,218 bytes |
コンパイル時間 | 2,338 ms |
コンパイル使用メモリ | 208,164 KB |
最終ジャッジ日時 | 2025-02-21 18:12:35 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<pair<ll,ll>> a(n); for(auto &&[x, y] : a){ cin >> x >> y; x *= 2, y *= 2; } vector<tuple<ll,ll,ll,ll>> b, c; for(int i = 0; i < n; i++){ auto &&[x1, y1] = a[i]; for(int j = i + 1; j < n; j++){ auto &&[x2, y2] = a[j]; ll dx = x2 - x1; ll dy = y2 - y1; ll g = gcd(abs(dx), abs(dy)); dx /= g, dy /= g; if(dx < 0) dx *= -1, dy *= -1; if(dx == 0) dy = abs(dy); if(dy == 0) dx = abs(dx); b.emplace_back((x1 + x2) / 2, (y1 + y2) / 2, dx, dy); dy *= -1; swap(dx, dy); if(dx < 0) dx *= -1, dy *= -1; if(dx == 0) dy = abs(dy); if(dy == 0) dx = abs(dx); c.emplace_back((x1 + x2) / 2, (y1 + y2) / 2, dx, dy); } } sort(c.begin(), c.end()); ll ans = 0; for(auto &&tup : b){ ans += upper_bound(c.begin(), c.end(), tup) - lower_bound(c.begin(), c.end(), tup); } cout << ans / 2 << '\n'; }