Codeforces Round #837 (Div. 2) 1771A Hossam and Combinatorics Solution



 Problem Link:  https://codeforces.com/contest/1771/problem/A

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. #define ll long long int
  10. int main()
  11. {
  12. ios_base::sync_with_stdio(0);
  13. cin.tie(0);
  14. ll n,i,t,j ;
  15. cin>>t;
  16. while(t--)
  17. {
  18. cin>>n;
  19. ll a[n+1];
  20. set<ll>st;
  21. ll mn=1e9,mx=0;
  22. map<ll,ll>mp;
  23. for(i=0; i<n; i++)
  24. {
  25. cin>>a[i];
  26. st.insert(a[i]);
  27. mp[a[i]]++;
  28. mn=min(a[i],mn);
  29. mx=max(a[i],mx);
  30. }
  31. ll x=mp[mn],y=mp[mx],ans=0;
  32. for(i=1; i<=x; i++)
  33. {
  34. for(j=1; j<=y; j++)
  35. {
  36. ans+=2;
  37. }
  38. }
  39. if(st.size()==1)cout<<n*(n-1)<<endl;
  40. else
  41. cout<<ans<<endl;
  42. }
  43. return 0;
  44. }

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.