fork(2) download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <set>
  5. #include <unordered_map>
  6. #include <iomanip>
  7. using namespace std;
  8.  
  9. int main() {
  10. // your code goes here
  11. ios::sync_with_stdio(false);
  12. int n;
  13. cin>>n;
  14. vector<int> v;
  15. for(int i = 0 ; i< n ; i++){
  16. int temp;
  17. cin>>temp;
  18. v.push_back(temp);
  19. }
  20. int diff[5001]={0};
  21. sort(v.begin(),v.end());
  22. reverse(v.begin(),v.end());
  23. for(int i = 0 ; i < n-1 ; i++)
  24. for(int j = i+1; j<n ; j++)
  25. diff[v[i]-v[j]]++;
  26. long long def[5001]={0};
  27. for(int i = 1; i< 5001; i++)
  28. for(int j = 1; j<5001; j++)
  29. if(diff[i]&&diff[j]&&i+j<5001)
  30. def[i+j]+=(diff[i]*diff[j]);
  31.  
  32. double ways = 0;
  33. for(int i = 1; i<5001; i++)
  34. if(diff[i])
  35. for(int j = i-1; j>0; j--)
  36. ways+=diff[i]*def[j];
  37.  
  38. double tt = ((n*(n-1))/2);
  39. double d = tt*tt*tt;
  40. cout.precision(10);
  41. cout<<setprecision(6)<<fixed<<ways/d;
  42. return 0;
  43. }
Success #stdin #stdout 0.05s 3412KB
stdin
3
1 2 10
stdout
0.074074