#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair #define F first #define S second int main() { ll n,m,k,i,j,l,sum,x,w,h,x1=0,x2=0,f,y,g; cin>>n; ll a[n-1]; ll b[n-1]; ll t[n]={0}; for(i=0;i<n-1;i++) cin>>a[i]; for(i=0;i<n-1;i++) cin>>b[i]; f=0; g=0; for(j=0;j<=3;j++) { for(k=0;k<=3;k++) { if(((j|k)==a[0])&&((j&k)==b[0])) { g=1; t[0]=k; x1=k; t[1]=j; x2=j; f=1; break; } } } // cout<<t[0]<<" "<<t[1]<<" "<<f; for(i=2;i<n;i++) { f=0; for(j=0;j<=3;j++) { // cout<<t[i-1]<<" t[] "; x=j|t[i-1]; y=j&t[i-1]; // cout<<x<<" x "<<y<<" y \n"; if((x==a[i-1])&&(y==b[i-1])) { //cout<<" ye "; t[i]=j; f=1; break; } } } if((g==1)&&(f==0)) { t[0]=x2; t[1]=x1; for(i=2;i<n;i++) { f=0; for(j=0;j<=3;j++) { // cout<<t[i-1]<<" t[] "; x=(j|t[i-1]); y=(j&t[i-1]); // cout<<x<<" x "<<y<<" y \n"; if((x==a[i-1])&&(y==b[i-1])) { //cout<<" ye "; t[i]=j; f=1; break; } } } } if(f==0) cout<<"NO"<<endl; else { cout<<"YES"<<endl; for(i=0;i<n;i++) { cout<<t[i]<<" "; } } return 0; }
Asked by: Manish_Kumar_Savita on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.