-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbit_manip.cpp
46 lines (43 loc) · 963 Bytes
/
bit_manip.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <bits/stdc++.h>
//Link:http://codeforces.com/contest/1072/problem/B
//Rohan Talwar's solution
using namespace std;
int main()
{
int n,i;
cin>>n;
int a[n-1],b[n-1];
for(i=0;i<n-1;i++) cin>>a[i];
for(i=0;i<n-1;i++) cin>>b[i];
for(i=0;i<n-1;i++)
{
if(a[i]<b[i])
{
cout<<"NO"<<'\n';
return 0;
}
}
int t[n];
for(int j=0;j<4;j++){
t[0]=j;
for(i=1;i<n;i++)
t[i]=a[i-1]+b[i-1]-t[i-1];
int sw=1;
for(i=0;i<n-1;i++)
{
if((t[i]|t[i+1])!=a[i] || (t[i]&t[i+1])!=b[i] || t[i+1]<0 || t[i+1]>3)
{ //cout<<i<<" "<<t[i]<<" "<<t[i+1]<<" "<<t[i]<<'\n';
sw=0;
break;
}
}
if(sw==1)
{
cout<<"YES"<<'\n';
for(i=0;i<n;i++)
cout<<t[i]<<' ';
return 0;
}
}
cout<<"NO"<<'\n';
}