Interview

Crawling in process...
Crawling failed
Time Limit:1000MS    
Memory Limit:262144KB    
64bit IO Format:
%I64d & %I64u

Description

Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem.

We define function f(x, l, r) as a bitwise OR of integers
xl, xl + 1, ..., xr,
where xi is the
i-th element of the array
x. You are given two arrays a and
b of length n. You need to determine the maximum value of sum
f(a, l, r) + f(b, l, r) among all possible
1 ≤ l ≤ r ≤ n.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the length of the arrays.

The second line contains n integers
ai (0 ≤ ai ≤ 109).

The third line contains n integers
bi (0 ≤ bi ≤ 109).

Output

Print a single integer — the maximum value of sum f(a, l, r) + f(b, l, r) among all possible
1 ≤ l ≤ r ≤ n.

Sample Input

Input
5
1 2 4 3 2
2 3 3 12 1
Output
22
Input
10
13 2 7 11 8 4 9 8 5 1
5 7 18 9 2 3 0 11 8 6
Output
46

Sample Output

Hint

Bitwise OR of two non-negative integers a and
b is the number c = aORb, such that each of its digits in binary notation is
1 if and only if at least one of
a or b have
1 in the corresponding position in binary notation.

In the first sample, one of the optimal answers is l = 2 and
r = 4, because f(a, 2, 4) + f(b, 2, 4) = (2
OR 4 OR 3) + (3 OR 3 OR 12) = 7 + 15 = 22. Other ways to get maximum value is to choose
l = 1 and r = 4,
l = 1 and r = 5,
l = 2 and r = 4,
l = 2 and r = 5,
l = 3 and r = 4, or
l = 3 and r = 5.

In the second sample, the maximum value is obtained for
l = 1 and r = 9.

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
__int64 num1[1010],num2[1010];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(num1,0,sizeof(num1));
memset(num2,0,sizeof(num2));
for(int i=1;i<=n;i++)
{
cin>>num1[i];
if(i>1) num1[1]|=num1[i];
} for(int i=1;i<=n;i++)
{
cin>>num2[i];
if(i>1) num2[1]|=num2[i];
}
cout<<num1[1]+num2[1]<<endl;
}
return 0;
}

Codeforces--631A--Interview(位运算)的更多相关文章

  1. CodeForces 282C(位运算)

    C. XOR and OR time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  2. codeforces 631A Interview

    A. Interview time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  3. Codeforces 631A Interview【模拟水题】

    题意: 模拟模拟~~ 代码: #include<iostream> using namespace std; const int maxn = 1005; int a[maxn], b[m ...

  4. Codeforces 868D Huge Strings - 位运算 - 暴力

    You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...

  5. 图论/位运算 Codeforces Round #285 (Div. 2) C. Misha and Forest

    题目传送门 /* 题意:给出无向无环图,每一个点的度数和相邻点的异或和(a^b^c^....) 图论/位运算:其实这题很简单.类似拓扑排序,先把度数为1的先入对,每一次少一个度数 关键在于更新异或和, ...

  6. Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维

    & -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...

  7. Divide by Zero 2021 and Codeforces Round #714 (Div. 2) B. AND Sequences思维,位运算 难度1400

    题目链接: Problem - B - Codeforces 题目 Example input 4 3 1 1 1 5 1 2 3 4 5 5 0 2 0 3 0 4 1 3 5 1 output 6 ...

  8. Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] A. Raising Bacteria【位运算/二进制拆分/细胞繁殖,每天倍增】

    A. Raising Bacteria time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #443 (Div. 2) C 位运算

    C. Short Program time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  10. Codeforces 620E New Year Tree(线段树+位运算)

    题目链接 New Year Tree 考虑到$ck <= 60$,那么用位运算统计颜色种数 对于每个点,重新标号并算出他对应的进和出的时间,然后区间更新+查询. 用线段树来维护. #includ ...

随机推荐

  1. 梦想CAD控件 2019.05.05更新

    下载地址: http://www.mxdraw.com/ndetail_20141.html 1. 增加vs2017版本控件 2. 增加windows触摸屏支持 3. 增加手写签名功能 4. 修改PL ...

  2. Vue组件传值方法调用

    1.子组件改变父组件的值 <father  label="云盘快照" name="name2"> <son :props='rows'   @ ...

  3. jquery 五星评价(图片实现)

    1111 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...

  4. swift中使用对象归档进行数据本地

    对象归档是ios持久化中的其中一种,也是很常用的一种.现在来看看swift是如何实现的.实现要点1),必须实现NSCoding的协议 import UIKit let path=(NSSearchPa ...

  5. ionic3开发环境搭建与配置(win10系统)

    1.安装nodeJS(不会的自行百度) 2.安装ionic和cordova,执行以下命令: npm install -g ionic cordova 3.安装Java JDK: 下载地址:http:/ ...

  6. Python使用Flask框架,结合Highchart处理csv数据(引申-从文件获取数据--从数据库获取数据)

    参考链接:https://www.highcharts.com.cn/docs/process-text-data-file 1.javascript代码 var options = { chart: ...

  7. ubuntu中mysql忘记密码如何修改

    1.在终端进入安装目录下:cd /etc/mysql 2.sudo cat debian.cnf 输入密码 3用如下图用户和密码登录 4.进入mysql use mysql 5.使用describe ...

  8. MySQL6

    MySQL数据库6 1. 集群概述 性能达到瓶颈的解决方案 Scale Up 向上扩展能力,如增加更好的硬件固态磁盘,加大内存等,成本高,效果不显著 Scale Out 向外扩展,例如建立更多的服务器 ...

  9. buf.readUInt32BE()函数详解

    buf.readUInt32BE(offset[, noAssert]) buf.readUInt32LE(offset[, noAssert]) offset {Number} 0 noAssert ...

  10. 正确的在循环list的时候删除list里面的元素

    s = [1,2,3,4,5] for i in s: s.remove(i) print(s)   输出结果:[2, 4] 1.当第一次删除后,后面的元素会前移,此时s=[2,3,4,5], 2.然 ...