Iamtui1010

distanceofpairs.cpp

Mar 14th, 2022
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3.  
  4. #pragma GCC optimize("03")
  5. #pragma GCC target("avx2")
  6.  
  7. #define long long long
  8. #define nln '\n'
  9.  
  10. using namespace std;
  11.  
  12. long sqr(long x)
  13. {
  14.     return x*x;
  15. }
  16.  
  17. long distance(pair<long, long> a, pair<long, long> b)
  18. {
  19.     return sqr(b.first-a.first) + sqr(b.second-a.second);
  20. }
  21.  
  22. int main()
  23. {
  24.     cin.tie(0)->sync_with_stdio(0);
  25.     cout.tie(0)->sync_with_stdio(0);
  26.     // Input
  27.     //freopen("distanceofpairs.inp", "r", stdin);
  28.     long n;
  29.     cin >> n;
  30.     vector<pair<long, long>> a(n);
  31.     for (auto &i : a)
  32.         cin >> i.first >> i.second;
  33.     // Process
  34.     long ans = 0;
  35.     for (long i = 0; i < n-1; ++i)
  36.         for (long j = i+1; j < n; ++j)
  37.             ans += distance(a[i], a[j]);
  38.     // Output
  39.     cout << ans << nln;
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment