Codeforces Round 858 (Div. 2) 1806B - Mex Master Solution

                                         

Problem Link : https://codeforces.com/contest/1806/problem/B

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. int32_t main() {
  10. ios_base::sync_with_stdio(0);
  11. cin.tie(0);
  12. int test ;
  13. cin >> test ;
  14. while ( test-- ){
  15. int n ;
  16. cin >> n ;
  17. int a, zcnt = 0 , ancnt = 0 ;
  18. for (int i = 0 ; i < n ; i++ ) {
  19. cin >> a ;
  20. if ( a == 0 ) zcnt++ ;
  21. else if ( a >= 2 ) ancnt++ ;
  22. }
  23. if ( zcnt <= ((n+1)/2)) {
  24. cout << "0" << endl;
  25. }
  26. else if (ancnt > 0 || zcnt == n ) {
  27. cout << "1" << endl;
  28. }
  29. else {
  30. cout << "2" << endl;
  31. }
  32. }
  33. return 0 ;
  34. }

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.