Codeforces Round 858 (Div. 2) 1806B - Mex Master Solution
Problem Link : https://codeforces.com/contest/1806/problem/B
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std ;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int test ;
- cin >> test ;
- while ( test-- ){
- int n ;
- cin >> n ;
- int a, zcnt = 0 , ancnt = 0 ;
- for (int i = 0 ; i < n ; i++ ) {
- cin >> a ;
- if ( a == 0 ) zcnt++ ;
- else if ( a >= 2 ) ancnt++ ;
- }
- if ( zcnt <= ((n+1)/2)) {
- cout << "0" << endl;
- }
- else if (ancnt > 0 || zcnt == n ) {
- cout << "1" << endl;
- }
- else {
- cout << "2" << endl;
- }
- }
- return 0 ;
- }
No comments