Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- const int N = 1e5 + 7;
- int a[N], b[N];
- bool f[N][6];
- int32_t main(){
- iostream::sync_with_stdio(0);
- int n;
- cin >> n;
- for(int i = 0; i < n - 1; i++)
- cin >> a[i];
- for(int i = 0; i < n - 1; i++)
- cin >> b[i];
- f[0][0] = true;
- f[0][1] = true;
- f[0][2] = true;
- f[0][3] = true;
- for(int i = 1; i < n; i++)
- for(int j = 0; j < 4; j++)
- for(int pr = 0; pr < 4; pr ++)
- if(f[i-1][pr] && (pr | j) == a[i - 1] && (pr & j) == b[i - 1])
- f[i][j] = true;
- for(int i = 0; i < n; i++)
- {
- bool res = false;
- for(int j = 0; j < 4; j++)
- res |= f[i][j];
- if(!res){
- cout << "NO";
- return 0;
- }
- }
- cout << "YES" << endl;
- vector<int> v;
- for(int i = n-1; i >= 0; i--)
- for(int j = 0; j < 4; j++)
- if(f[i][j] && (!v.size() | (v.size() && (v.back() & j) == b[i] && (v.back() & j) == b[i])))
- {
- v.push_back(j);
- break;
- }
- reverse(v.begin(), v.end());
- for(auto i : v)
- cout << i << ' ';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement