0%

Codeforces Round 517 (Div. 2) B题

题目链接

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
47
48
49
50
51
//2021-05-22 20:08:28
#include <bits/stdc++.h>
using namespace std;

const int N = 100001;

int n;
int a[N], b[N], c[N];
/*
a[1]=11 c[1]=01 c[2]=10
b[1]=01 c[1]=01 c[2]=11

*/

int dfs(int step, int lst){
if(step == n+1) return 1;
for(int i = 0; i <= 3; i++){
if((lst|i) == a[step-1] && (lst&i) == b[step-1] && dfs(step+1, i)){
c[step] = i;
return 1;
}
}
return 0;
}

int main(){
scanf("%d", &n);
for(int i = 1; i < n; i++){
scanf("%d", &a[i]);
}
for(int i = 1; i < n; i++){
scanf("%d", &b[i]);
}

for(int i = 0; i <= 3; i++) {
if(dfs(2 ,i)){
c[1] = i;
cout << "YES" << endl;
for(int j = 1; j <= n; j++){
cout << c[j] << ' ';
}return 0;
}
}
cout << "NO";
//01 10 11


return 0;
}


求大佬赏个饭