Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef vector<int> vi;
- void solve() {
- int n;
- ll k;
- cin >> n >> k;
- vector<ll> arr(n);
- for (int i = 0; i < n; i++) cin >> arr[i];
- vector<int> indices;
- for (int i = 0; i < n; i++) {
- if ((arr[i] & k) == k) { // Elements that have all k's bits set
- indices.push_back(i + 1);
- }
- }
- if (indices.empty()) {
- cout << "NO\n";
- return;
- }
- int m = indices.size();
- for (int len = 1; len <= m; len++) {
- ll curr_and = arr[indices[0] - 1];
- bool found = false;
- for (int i = 1; i < len; i++) {
- curr_and &= arr[indices[i] - 1];
- }
- if (curr_and == k) {
- cout << "YES\n" << len << "\n";
- for (int i = 0; i < len; i++) {
- cout << indices[i] << (i == len-1 ? "\n" : " ");
- }
- return;
- }
- }
- cout << "NO\n";
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- int t;
- cin >> t;
- while (t--) solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement