CF1031B.Curiosity Has No Limits

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 aia_i (0≤ai≤30 \le a_i \le 3), and the elements of the second sequence as bib_i (0≤bi≤30 \le b_i \le 3).

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

  • ai=ti∣ti+1a_i = t_i | t_{i + 1} (where ∣| denotes the bitwise OR operation) and
  • bi=ti&ti+1b_i = t_i \& t_{i + 1} (where &\& denotes the bitwise AND operation).

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

今天玛莎来到数学课时,发现黑板上有两个长度为 n−1n - 1 的整数序列。我们记第一个序列的元素为 aia_i(0≤ai≤30 \le a_i \le 3),第二个序列的元素为 bib_i(0≤bi≤30 \le b_i \le 3)。

玛莎开始好奇:是否存在一个长度为 nn 的整数序列,其元素记为 tit_i(0≤ti≤30 \le t_i \le 3),使得对每个 ii(1≤i≤n−11 \le i \le n - 1)均满足以下条件:

  • ai=ti∣ti+1a_i = t_i | t_{i + 1}(其中 ∣| 表示按位或运算),且
  • bi=ti&ti+1b_i = t_i \& t_{i + 1}(其中 &\& 表示按位与运算)。

这个问题对玛莎来说太难了,因此她请你帮忙判断这样的序列 tit_i 是否存在。如果存在,请构造出一个这样的序列;如果存在多个解,则输出任意一个即可。

输入格式

The first line contains a single integer nn (2≤n≤1052 \le n \le 10^5) — the length of the sequence tit_i.

The second line contains n−1n - 1 integers a1,a2,…,an−1a_1, a_2, \ldots, a_{n-1} (0≤ai≤30 \le a_i \le 3) — the first sequence on the blackboard.

The third line contains n−1n - 1 integers b1,b2,…,bn−1b_1, b_2, \ldots, b_{n-1} (0≤bi≤30 \le b_i \le 3) — the second sequence on the blackboard.

第一行包含一个整数 nn(2≤n≤1052 \le n \le 10^5)——序列 tit_i 的长度。

第二行包含 n−1n - 1 个整数 a1,a2,…,an−1a_1, a_2, \ldots, a_{n-1}(0≤ai≤30 \le a_i \le 3)——黑板上的第一个序列。

第三行包含 n−1n - 1 个整数 b1,b2,…,bn−1b_1, b_2, \ldots, b_{n-1}(0≤bi≤30 \le b_i \le 3)——黑板上的第二个序列。

输出格式

In the first line print "YES" (without quotes), if there is a sequence tit_i 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,…,tnt_1, t_2, \ldots, t_n (0≤ti≤30 \le t_i \le 3) — the sequence that satisfies the statements conditions.

If there are multiple answers, print any of them.

第一行输出 "YES"(不带引号),如果存在满足题目条件的序列 tit_i;否则输出 "NO"(不带引号)。

如果存在这样的序列,则在第二行输出 nn 个整数 t1,t2,…,tnt_1, t_2, \ldots, t_n(其中 0≤ti≤30 \le t_i \le 3)—— 即满足题目条件的序列。

若存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#1

    4
    3 3 2
    1 2 0

    输出#1

    YES
    1 3 2 0
  • 输入#2

    3
    1 3
    3 2

    输出#2

    NO

说明/提示

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

  • t1∣t2=(012)∣(112)=(112)=3=a1t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1 and t1&t2=(012)&(112)=(012)=1=b1t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1;
  • t2∣t3=(112)∣(102)=(112)=3=a2t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2 and t2&t3=(112)&(102)=(102)=2=b2t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2;
  • t3∣t4=(102)∣(002)=(102)=2=a3t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3 and t3&t4=(102)&(002)=(002)=0=b3t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3.

In the second example there is no such sequence.

在第一个例子中,很容易看出输出序列满足给定条件:

  • t1∣t2=(012)∣(112)=(112)=3=a1t_1 | t_2 = (01_2) | (11_2) = (11_2) = 3 = a_1,且 t1&t2=(012)&(112)=(012)=1=b1t_1 \& t_2 = (01_2) \& (11_2) = (01_2) = 1 = b_1;
  • t2∣t3=(112)∣(102)=(112)=3=a2t_2 | t_3 = (11_2) | (10_2) = (11_2) = 3 = a_2,且 t2&t3=(112)&(102)=(102)=2=b2t_2 \& t_3 = (11_2) \& (10_2) = (10_2) = 2 = b_2;
  • t3∣t4=(102)∣(002)=(102)=2=a3t_3 | t_4 = (10_2) | (00_2) = (10_2) = 2 = a_3,且 t3&t4=(102)&(002)=(002)=0=b3t_3 \& t_4 = (10_2) \& (00_2) = (00_2) = 0 = b_3。

在第二个例子中,不存在满足条件的序列。

输入解题思路,AI测评打分。不知道怎么写?

首页