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 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.