http://codeforces.com/contest/1072/problem/B

B. Curiosity Has No Limits

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

When Masha came to math classes today, she saw two integer sequences of length n−1n−1 on the blackboard. Let's denote the elements of the first sequence as aiai (0≤ai≤30≤ai≤3), and the elements of the second sequence as bibi (0≤bi≤30≤bi≤3).

Masha became interested if or not there is an integer sequence of length nn, which elements we will denote as titi (0≤ti≤30≤ti≤3), so that for every ii (1≤i≤n−11≤i≤n−1) the following is true:

The question appeared to be too difficult for Masha, so now she asked you to check whether such a sequence titi of length nn exists. If it exists, find such a sequence. If there are multiple such sequences, find any of them.

Input

The first line contains a single integer nn (2≤n≤1052≤n≤105) — the length of the sequence titi.

The second line contains n−1n−1 integers a1,a2,…,an−1a1,a2,…,an−1 (0≤ai≤30≤ai≤3) — the first sequence on the blackboard.

The third line contains n−1n−1 integers b1,b2,…,bn−1b1,b2,…,bn−1 (0≤bi≤30≤bi≤3) — the second sequence on the blackboard.

Output

In the first line print "YES" (without quotes), if there is a sequence titi that satisfies the conditions from the statements, and "NO" (without quotes), if there is no such sequence.

If there is such a sequence, on the second line print nn integers t1,t2,…,tnt1,t2,…,tn (0≤ti≤30≤ti≤3) — the sequence that satisfies the statements conditions.

If there are multiple answers, print any of them.

Examples
input

Copy
4
3 3 2
1 2 0
output

Copy
YES
1 3 2 0
input

Copy
3
1 3
3 2
output

Copy
NO
Note

In the first example it's easy to see that the sequence from output satisfies the given conditions:

  • t1|t2=(012)|(112)=(112)=3=a1t1|t2=(012)|(112)=(112)=3=a1 and t1&t2=(012)&(112)=(012)=1=b1t1&t2=(012)&(112)=(012)=1=b1;
  • t2|t3=(112)|(102)=(112)=3=a2t2|t3=(112)|(102)=(112)=3=a2 and t2&t3=(112)&(102)=(102)=2=b2t2&t3=(112)&(102)=(102)=2=b2;
  • t3|t4=(102)|(002)=(102)=2=a3t3|t4=(102)|(002)=(102)=2=a3 and t3&t4=(102)&(002)=(002)=0=b3t3&t4=(102)&(002)=(002)=0=b3.

In the second example there is no such sequence.

题意:求一个n长度的t数组,满足t[i]&t[i+1] == b[i]   同时 t[i]|t[i+1] == a[i]。 a,b数组长度为n-1

枚举法,想过枚举但是没有想到是这样做的。因为t数组中,最后一个是最特殊的,只与a和b数组中的一个元素相关(自己没有发现)。同时没有发现如果确定了一个点,那么下一个点的值是唯一确定的。这样想来,其实枚举第一个也是可行的了。

同时,需要记住,如果t[i]确定了,那么与不同的t[i+1]进行或,与运算一定会得到的是不同的结果。

和之前做过的一道Fliptile有些像。

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#define ll long long
//#define local using namespace std; const int MOD = 1e9+;
const int inf = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int maxn = (1e5+);
const int maxedge = *;
int a[maxn], b[maxn];
int t[maxn]; int main() {
#ifdef local
if(freopen("/Users/Andrew/Desktop/data.txt", "r", stdin) == NULL) printf("can't open this file!\n");
#endif
int n;
scanf("%d", &n);
for (int i = ; i < n-; ++i) {
scanf("%d", a+i);
}
for (int i = ;i < n-; ++i) {
scanf("%d", b+i);
}
for (int i = ; i < ; ++i) {
memset(t, -, sizeof(t));
t[n-] = i;
for (int j = n-; j >= ; --j) {
for (int k = ; k < ; ++k) {
if ((k|t[j+])==a[j] && (k&t[j+])==b[j]) {
t[j] = k;
break;
}
}
if (t[j] == -) break;
}
if (t[] != -) break;
}
if (t[] == -) printf("NO\n");
else {
printf("YES\n");
for (int i = ; i < n; ++i) {
printf("%d", t[i]);
if (i != n-) printf(" ");
}
printf("\n");
}
#ifdef local
fclose(stdin);
#endif
return ;
}
 

CodeForce 517 Div 2. B Curiosity Has No Limits的更多相关文章

  1. CodeForce 517 Div 2. C Cram Time

    http://codeforces.com/contest/1072/problem/C C. Cram Time time limit per test 1 second memory limit ...

  2. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2)

    Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) #include <bits/stdc++ ...

  3. CF-1027-B. Curiosity Has No Limits

    CF-1027-B. Curiosity Has No Limits http://codeforces.com/contest/1072/problem/B 题意: 给定两组序列a,b,长度为n-1 ...

  4. Codeforce#331 (Div. 2) A. Wilbur and Swimming Pool(谨以此题来纪念我的愚蠢)

    C time limit per test 1 second memory limit per test 256 megabytes input standard input output stand ...

  5. 【LCA】CodeForce #326 Div.2 E:Duff in the Army

    C. Duff in the Army Recently Duff has been a soldier in the army. Malek is her commander. Their coun ...

  6. CODEFORCE 246 Div.2 B题

    题目例如以下: B. Football Kit time limit per test 1 second memory limit per test 256 megabytes input stand ...

  7. Codeforces Round #517 Div. 2/Div. 1

    \(n\)天没更博了,因为被膜你赛的毒瘤题虐哭了... 既然打了这次CF还是纪念一下. 看看NOIP之前,接下来几场的时间都不好.这应该是最后一场CF了,差\(4\)分上紫也是一个遗憾吧. A 给一个 ...

  8. Codeforces Round #517 (Div. 2)

    A #include<queue> #include<cstdio> #include<cstring> #include<algorithm> #de ...

  9. Codeforces Round #517 (Div. 2, based on Technocup 2019 Elimination Round 2) D. Minimum path

    http://codeforces.com/contest/1072/problem/D bfs 走1步的最佳状态 -> 走2步的最佳状态 -> …… #include <bits/ ...

随机推荐

  1. 通过Python计算一个文件夹大小

    在进行计算一个文件夹内容大小的时候,我们要考虑文件夹内都有什么内容,可能都是一个一个的单文件,也有可能都是子文件夹,或者二者都有,既然要计算整个文件夹的大小,我们当然要计算每一个文件的大小以及每一个子 ...

  2. 聚合函数与F/Q表达式

    聚合函数 取名: field + __ + 聚合函数名字 ,如:price__avg:可传关键字参数修改名字:avg=Avg("price"): aggregate:不会返回一个  ...

  3. CookieHelper

    using System.Web: /// <summary> /// CookieHelper /// </summary> public static class Cook ...

  4. 智能合约 helloworld

    windows 平台 所以直接使用Remix在线编译环境 新建hello.sol文件 编辑如下 Remix 右边侧栏 setting 选择合适的编译器版本 这里选择 0.4.19 文件中输入如下内容  ...

  5. word->excel数据处理

    朋友发来一个word文件,里面的数据没有分割,想分割后放到excel统计 通常遇到这种数据,首先想到每一列数据有没有什么特征 类似这种数据,一种办法是按位数截取,mid函数,或者按第一次出现数字的方式 ...

  6. 用GraphX分析伴生网络(一)

    1. 图论与GraphX 图论是一个数学学科,研究一组实体(称为顶点)之间两两关系(称为边)的特点.通过构建关系图谱,并对关系进行分析,可以实现更好的投放广告,推荐关系等.随着关系图谱越来越强大,计算 ...

  7. fast-route的使用

    <?php require 'vendor/autoload.php'; // 通过 FastRoute\simpleDispatcher() 方法定义路由,第一个参数必须是 FastRoute ...

  8. JavaScript基础四

    1.13 Js中的面向对象 1.13.1 创建对象的几种常用方式 1.使用Object或对象字面量创建对象 2.工厂模式创建对象 3.构造函数模式创建对象 4.原型模式创建对象 1.使用Object或 ...

  9. gnu make - 初学

    因为要为Linux平台编译ACE,按照ACE的文档如何编译部分的说明,要求使用gnu make.其原文档说明如下: Using the Traditional ACE/GNU Configuratio ...

  10. M0内核的STM32实现比较精准的延时

    #include "drv_delay.h"#include "core_cm0plus.h" //我的系统时钟设置为4MHz /*************** ...