classSolution { public: intcountElements(vector<int>& nums){ int Mx = *max_element(begin(nums), end(nums)), Mn = *min_element(begin(nums), end(nums)); int ans = 0; for (auto& c : nums) { if (c != Mx and c != Mn) ans ++ ; } return ans; } };
classSolution { public: intmaximumGood(vector<vector<int>>& nums){ int n = nums.size(); int ans = 0; vector<vector<int>> state(n); for (int i = 0; i < n; i ++ ) { int good = 0, bad = 0; for (int j = 0; j < n; j ++ ) { if (nums[i][j] == 1) good |= (1 << j); if (nums[i][j] == 0) bad |= (1 << j); } state[i].push_back(good); state[i].push_back(bad); } for (int i = 0; i < 1 << n; i ++ ) { int cnt = __builtin_popcount(i); int good = 0, bad = 0; for (int j = 0; j < n; j ++ ) { if (i >> j & 1) good |= (1 << j); else bad |= (1 << j); } bool flag = true; for (int j = 0; j < n; j ++ ) { if (i >> j & 1) { if ((state[j][0] | good) != good) flag = false; if ((state[j][1] | bad) != bad) flag = false; } } if (flag) ans = max(ans, cnt); } return ans; } };