A. Interview

题目连接:

http://www.codeforces.com/contest/631/problem/A

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

5

1 2 4 3 2

2 3 3 12 1

Sample Output

22

Hint

题意

给你2*n的矩阵

然后定义一个函数f(a,l,r)表示a数组在l到r的或值

然后让你找到一对l,r,使得f(a,l,r)+f(b,l,r)最大

题解:

由于是或嘛,所以就把所有数全部或起来

代码

#include<bits/stdc++.h>
using namespace std; long long ans = 0;
int main()
{
int n;
scanf("%d",&n);
long long tmp = 0;
for(int i=1;i<=n;i++)
{
long long x;
scanf("%lld",&x);
tmp|=x;
}
ans+=tmp;
tmp = 0;
for(int i=1;i<=n;i++)
{
long long x;
scanf("%lld",&x);
tmp|=x;
}
ans+=tmp;
cout<<ans<<endl;
}

Codeforces Round #344 (Div. 2) A. Interview 水题的更多相关文章

  1. Codeforces Round #344 (Div. 2) A. Interview

    //http://codeforces.com/contest/631/problem/Apackage codeforces344; import java.io.BufferedReader; i ...

  2. Codeforces Round #185 (Div. 2) B. Archer 水题

    B. Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/problem/B D ...

  3. Codeforces Round #360 (Div. 2) A. Opponents 水题

    A. Opponents 题目连接: http://www.codeforces.com/contest/688/problem/A Description Arya has n opponents ...

  4. Codeforces Round #190 (Div. 2) 水果俩水题

    后天考试,今天做题,我真佩服自己... 这次又只A俩水题... orz各路神犇... 话说这次模拟题挺多... 半个多小时把前面俩水题做完,然后卡C,和往常一样,题目看懂做不出来... A: 算是模拟 ...

  5. Codeforces Round #256 (Div. 2/A)/Codeforces448A_Rewards(水题)解题报告

    对于这道水题本人觉得应该应用贪心算法来解这道题: 下面就贴出本人的代码吧: #include<cstdio> #include<iostream> using namespac ...

  6. Codeforces Round #340 (Div. 2) B. Chocolate 水题

    B. Chocolate 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co Bob loves everyt ...

  7. Codeforces Round #340 (Div. 2) A. Elephant 水题

    A. Elephant 题目连接: http://www.codeforces.com/contest/617/problem/A Descriptionww.co An elephant decid ...

  8. Codeforces Round #340 (Div. 2) D. Polyline 水题

    D. Polyline 题目连接: http://www.codeforces.com/contest/617/problem/D Descriptionww.co There are three p ...

  9. Codeforces Round #338 (Div. 2) A. Bulbs 水题

    A. Bulbs 题目连接: http://www.codeforces.com/contest/615/problem/A Description Vasya wants to turn on Ch ...

随机推荐

  1. netcat、nc工具随记

    netcat又称nc工具,其最主要的作用就是建立连接并返回两个数据流,剩下的就看各位的想象力了,想象力是很重要的,这也是这个工具的强大之处的所在,所以重要的东西才要说三遍,想象力! 具体参数如下: - ...

  2. GCC在C语言中内嵌汇编 asm __volatile__ 【转】

    转自:http://blog.csdn.net/pbymw8iwm/article/details/8227839 在内嵌汇编中,可以将C语言表达式指定为汇编指令的操作数,而且不用去管如何将C语言表达 ...

  3. $(document).ready 和 window.onload 的区别

    1.相同点 两者都用于在网页加载完后执行相应代码块. 2.不同点 window.onload 在创建完 DOM 树后,所有外部资源(图片.Flash 动画等)加载完成,且整个页面在浏览器窗口中显示完毕 ...

  4. Linux System.map文件【转】

    转自:http://blog.csdn.net/ysbj123/article/details/51233618 当运行GNU链接器gld(ld)时若使用了"-M"选项,或者使用n ...

  5. python基础===getattr()函数使用方法

    getattr(object, name[,default]) 获取对象object的属性或者方法,如果存在打印出来,如果不存在,打印出默认值,默认值可选.需要注意的是,如果是返回的对象的方法,返回的 ...

  6. python之requests库使用问题汇总

    一.请求参数类型 1.get requests.get(url, data, cookies=cookies) url:字符串: data:字典类型,可以为空: cookies:字典类型,可以为空: ...

  7. caffe Python API 之LRN

    net.mylrn = caffe.layers.LRN(net.pool1,local_size=5,alpha=1e-4,beta=0.75) 输出: layer { name: "my ...

  8. CSS3 icon font

    大家都知道现在各个浏览器都支持CSS3的自定义字体(@font-face),包括IE6都支持,只是各自对字体文件格式的支持不太一样.那么对于网站中用到的各种icon,我们就可以尝试使用font来实现, ...

  9. web中的CSS、Xpath等路径定位方法学习

    今天不到八点就到公司了,来的比较早,趁着有点时间,总结下web中的CSS.Xpath等路径定位定位的方式吧! 简单的介绍下xpath和css的定位 理论知识就不罗列了 还是利用博客园的首页.直接附上代 ...

  10. hihocoder 1178 : 计数

    #1178 : 计数 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Rowdark是一个邪恶的魔法师.在他阅读大巫术师Lich的传记时,他发现一类黑魔法来召唤远古生物, ...