CF1395C.Boboniu and Bit Operations

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Boboniu likes bit operations. He wants to play a game with you.

Boboniu gives you two sequences of non-negative integers a1,a2,…,ana_1,a_2,\ldots,a_n and b1,b2,…,bmb_1,b_2,\ldots,b_m.

For each ii (1≤i≤n1\le i\le n), you're asked to choose a jj (1≤j≤m1\le j\le m) and let ci=ai&bjc_i=a_i\& b_j, where &\& denotes the bitwise AND operation. Note that you can pick the same jj for different ii's.

Find the minimum possible c1∣c2∣…∣cnc_1 | c_2 | \ldots | c_n, where ∣| denotes the bitwise OR operation.

Boboniu 喜欢位运算。他想和你玩一个游戏。

Boboniu 给你两个非负整数序列 a1,a2,…,ana_1,a_2,\ldots,a_n 和 b1,b2,…,bmb_1,b_2,\ldots,b_m。

对于每个 ii(1≤i≤n1\le i\le n),你需要选择一个 jj(1≤j≤m1\le j\le m),并令 ci=ai&bjc_i=a_i\& b_j,其中 &\& 表示按位与运算。注意:对于不同的 ii,你可以选择相同的 jj。

求 c1∣c2∣…∣cnc_1 | c_2 | \ldots | c_n 的最小可能值,其中 ∣| 表示按位或运算。

输入格式

The first line contains two integers nn and mm (1≤n,m≤2001\le n,m\le 200).

The next line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (0≤ai<290\le a_i \lt 2^9).

The next line contains mm integers b1,b2,…,bmb_1,b_2,\ldots,b_m (0≤bi<290\le b_i \lt 2^9).

第一行包含两个整数 nn 和 mm(1≤n,m≤2001\le n,m\le 200)。

第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(0≤ai<290\le a_i \lt 2^9)。

第三行包含 mm 个整数 b1,b2,…,bmb_1,b_2,\ldots,b_m(0≤bi<290\le b_i \lt 2^9)。

输出格式

Print one integer: the minimum possible c1∣c2∣…∣cnc_1 | c_2 | \ldots | c_n.

输出一个整数:最小可能的 c1∣c2∣…∣cnc_1 | c_2 | \ldots | c_n。

输入输出样例

  • 输入#1

    4 2
    2 6 4 0
    2 4

    输出#1

    2
  • 输入#2

    7 6
    1 9 1 9 8 1 0
    1 1 4 5 1 4

    输出#2

    0
  • 输入#3

    8 5
    179 261 432 162 82 43 10 38
    379 357 202 184 197

    输出#3

    147

说明/提示

For the first example, we have c1=a1&b2=0c_1=a_1\& b_2=0, c2=a2&b1=2c_2=a_2\& b_1=2, c3=a3&b1=0c_3=a_3\& b_1=0, c4=a4&b1=0c_4 = a_4\& b_1=0.Thus c1∣c2∣c3∣c4=2c_1 | c_2 | c_3 |c_4 =2, and this is the minimal answer we can get.

对于第一个例子,我们有 c1=a1&b2=0c_1=a_1\& b_2=0,c2=a2&b1=2c_2=a_2\& b_1=2,c3=a3&b1=0c_3=a_3\& b_1=0,c4=a4&b1=0c_4 = a_4\& b_1=0。因此 c1∣c2∣c3∣c4=2c_1 | c_2 | c_3 |c_4 =2,这是我们可以得到的最小答案。

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

首页