fork download
  1. //#pragma GCC optimize("Ofast,unroll-loops")
  2. //#pragma GCC target("avx2,tune=native")
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. #define file "tripoint"
  7. #define ff(i, a, b) for(auto i=(a); i<=(b); ++i)
  8. #define ffr(i, b, a) for(auto i=(b); i>=(a); --i)
  9. #define nl "\n"
  10. #define ss " "
  11. #define pb emplace_back
  12. #define fi first
  13. #define se second
  14. #define sz(s) (int)s.size()
  15. #define all(s) (s).begin(), (s).end()
  16. #define ms(a,x) memset(a, x, sizeof (a))
  17. #define cn continue
  18. #define re return 0
  19.  
  20. typedef long long ll;
  21. typedef unsigned long long ull;
  22. typedef long double ld;
  23. typedef vector<int> vi;
  24. typedef vector<ll> vll;
  25. typedef pair<int, int> pii;
  26. typedef pair<ll, ll> pll;
  27. typedef vector<pii> vpii;
  28. typedef vector<pll> vpll;
  29.  
  30. mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
  31. ll ran(ll l, ll r)
  32. {
  33. return uniform_int_distribution<ll> (l, r)(rng);
  34. }
  35.  
  36. inline void rf()
  37. {
  38. ios_base::sync_with_stdio(false);
  39. cin.tie(nullptr); cout.tie(nullptr);
  40. if(fopen(file".inp","r"))
  41. {
  42. freopen(file".inp","r",stdin);
  43. freopen(file".out","w",stdout);
  44. }
  45. }
  46.  
  47. const int mod=998244353;
  48. const int maxn=2005;
  49. const ll inf=5e16;
  50.  
  51. template<typename T> inline void add(T &x, const T &y)
  52. {
  53. x+=y;
  54. if(x>=mod) x-=mod;
  55. if(x<0) x+=mod;
  56. }
  57.  
  58. template<typename T> inline bool maxi(T &a, T b)
  59. {
  60. if(a>=b) return 0;
  61. a=b; return 1;
  62. }
  63.  
  64. template<typename T> inline bool mini(T &a, T b)
  65. {
  66. if(a<=b) return 0;
  67. a=b; return 1;
  68. }
  69.  
  70. struct point{
  71. ll x,y;
  72. };
  73.  
  74. struct vect{
  75. ll x,y;
  76. };
  77.  
  78. ll my_gcd(ll a, ll b)
  79. {
  80. a = abs(a);
  81. b = abs(b);
  82. while (b) {
  83. a %= b;
  84. swap(a, b);
  85. }
  86. return a;
  87. }
  88.  
  89. vect create_vect(point p1,point p2)
  90. {
  91. ll dx = p2.x - p1.x;
  92. ll dy = p2.y - p1.y;
  93. ll u = my_gcd(dx, dy);
  94.  
  95. if (u == 0) u = 1;
  96.  
  97. if (dx < 0 || (dx == 0 && dy < 0)) {
  98. u = -u;
  99. }
  100.  
  101. return (vect){dx / u, dy / u};
  102. }
  103.  
  104.  
  105. int n;
  106. point a[maxn];
  107. unordered_map<ll,int> mp;
  108.  
  109. void prc1()
  110. {
  111. ll res=0;
  112. cin >> n;
  113. ff(i, 1, n)
  114. {
  115. cin >> a[i].x >> a[i].y;
  116. }
  117.  
  118. ff(i, 1, n)
  119. {
  120. mp.clear();
  121. ff(j, i+1, n)
  122. {
  123. vect vt=create_vect(a[i],a[j]);
  124. mp[vt.x*2000000000LL+vt.y]++;
  125. }
  126.  
  127. for(auto const& [key, count] : mp)
  128. {
  129. res+=(ll)count*((ll)count-1)/2;
  130. }
  131. }
  132. cout << res << nl;
  133. }
  134.  
  135. signed main()
  136. {
  137. rf();
  138. prc1();
  139. re;
  140. }
Success #stdin #stdout 0.01s 5320KB
stdin
6
0 0
0 1
0 2
1 1
1 2
2 2
stdout
3