結果

問題 No.2769 Number of Rhombi
ユーザー kusaf_kusaf_
提出日時 2024-06-04 01:38:15
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 959 ms / 5,000 ms
コード長 825 bytes
コンパイル時間 3,339 ms
コンパイル使用メモリ 258,604 KB
実行使用メモリ 81,408 KB
最終ジャッジ日時 2024-12-23 10:46:14
合計ジャッジ時間 30,091 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void grd(ll &dx, ll &dy) {
  ll g = gcd(dx, dy);
  dx /= g, dy /= g;
  if(dx < 0) { dx *= -1, dy *= -1; }
  if(!dx) { dy = 1; }
  if(!dy) { dx = 1; }
};

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

  ll N;
  cin >> N;

  vector<ll> x(N), y(N);
  for(ll i = 0; i < N; i++) { cin >> x[i] >> y[i]; }

  map<tuple<ll, ll, ll, ll>, ll> m;
  for(ll i = 0; i < N; i++) {
    for(ll j = 0; j < i; j++) {
      ll sx = x[i] + x[j], sy = y[i] + y[j];
      ll dx = x[i] - x[j], dy = y[i] - y[j];
      grd(dx, dy);
      m[{sx, sy, dx, dy}]++;
    }
  }

  ll ans = 0;
  for(auto &[v, c] : m) {
    auto &[sx, sy, dx, dy] = v;
    ll ndx = dy, ndy = -dx;
    grd(ndx, ndy);
    ans += c * m[{sx, sy, ndx, ndy}];
  }

  cout << ans / 2 << "\n";
}
0