Codeforces 862C - Mahmoud and Ehab and the xor

时间:2023-03-08 21:20:23
Codeforces 862C - Mahmoud and Ehab and the xor

862C - Mahmoud and Ehab and the xor

思路:找两对异或后等于(1<<17-1)的数(相当于加起来等于1<<17-1),两个再异或一下就变成0了,0异或x等于x。所以只要把剩下的异或起来变成x就可以了。如果剩下来有3个,那么,这3个数可以是x^i^j,i,j。

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N=1e7+;
bool vis[N]={false};
bool vs[]={false};
vector<int>ans;
vector<int>temp;
int n,x;
bool flag=false;
void dfs(int s,int t,int n)
{
if(flag)return ;
if(t==)
{
if(!vs[n])
{
for(int i=;i<temp.size();i++)
ans.pb(temp[i]),vis[temp[i]]=true;
ans.pb(n),vis[n]=true;
flag=true;
}
return ;
}
for(int i=s;i<;i++)
{
temp.pb(i);
vs[i]=true;
if(i!=x)dfs(i+,t-,n^i);
vs[i]=false;
temp.pop_back();
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int n,x;
cin>>n>>x;
if(n==&&x==)
{
cout<<"NO"<<endl;
return ;
}
int t=n%,t1=n-t;
if(t==&&n!=)t=,t1-=;
if(t==)t=,t1-=;
vis[x]=true;
dfs(,t-,x);
for(int i=;i<(<<);i++)
{
if(t1)
{
if((!vis[i])&&(!vis[-i]))
{
ans.pb(i);
ans.pb(-i);
vis[i]=vis[-i]=true;
t1-=;
}
}
else break;
}
cout<<"YES"<<endl;
for(int i=;i<ans.size();i++)
{
cout<<ans[i];
if(i!=ans.size())cout<<' ';
}
cout<<endl;
return ;
}