Untitled
unknown
plain_text
a year ago
920 B
6
Indexable
#include <bits/stdc++.h> using namespace std; #define ll long long int tt, tc; void solve() { int n; ll x; cin >> n >> x; vector<ll> a(n); for (ll& u : a) cin >> u; ll xoring = 0, anding = (1LL << 40) - 1; for (ll u : a) { xoring ^= u; anding &= u; } int operations = 0; if (xoring >= x) { cout << 0 << "\n"; return; } for (int bit = 31; bit >= 0; --bit) { if (((1LL << bit) & xoring) == 0) { if (((1LL << bit) & anding) == 0) { xoring |= (1LL << bit); operations++; } } if (xoring >= x) { cout << operations << "\n"; return; } } cout << -1 << "\n"; } int main() { ios::sync_with_stdio(0); cin.tie(0); tt = 1, tc = 1; // cin >> tt; while (tt--) solve(), tc++; }
Editor is loading...
Leave a Comment