2019-09-01 00:39:55 C++

C++

Copy Copied! Full
#include <bits/stdc++.h> using namespace std; #define ALL(A) (A).begin(),(A).end() #define ll long long const ll mod = 1e9+7; const ll INF = 2*1e18; const int inf = 1e9+7; int main(void){ int N,X,cnt; cin >> N >> X; vector<int> a(N),ans; int Y = X; for(int i=0;i<N;i++){ cin >> a[i]; Y ^= a[i]; if(a[i] == -1){ cnt++; ans.push_back(i); } } for(int i=0;i<cnt;i++){ int now = 0; for(int j=30;j>=0;j--){ if( ((1<<j)&Y )){ if( ((1<<j) + now )<=X){ Y-=(1<<j); now += (1<<j); } } } a[ans[cnt]] = now; } if(Y){ cout << -1 << endl; }else{ for(int i=0;i<N;i++){ if(i!=0)cout << " "; cout << a[i]; } cout << endl; } }
RECOMMEND