A. Interview
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples
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
Note

Bitwise OR of two non-negative integers a and b is the number c = a OR b, 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.

题解: max(f(a,l,r)+f((b,l,r))  f() 为求 l-->r的按位或的值

马上codeforces  上分

 #include<bits/stdc++.h>
using namespace std;
int a[][];
int b[][];
int exm1[],exm2[];
int main()
{
int n;
int sum1=,sum2=,maxn=;;
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&exm1[i]);
}
for(int i=; i<=n; i++)
{
scanf("%d",&exm2[i]);
}
for(int i=; i<=n; i++)
{
sum1=exm1[i];
a[i][i]=sum1;
for(int j=i+; j<=n; j++)
{
a[i][j]=sum1|exm1[j];
sum1=a[i][j];
}
}
for(int i=; i<=n; i++)
{
sum2=exm2[i];
b[i][i]=sum2;
if(b[i][i]+a[i][i]>maxn)
maxn=b[i][i]+a[i][i];
for(int j=i+; j<=n; j++)
{
b[i][j]=sum2|exm2[j];
sum2=b[i][j];
if(b[i][j]+a[i][j]>maxn)
maxn=b[i][j]+a[i][j];
}
}
printf("%d\n",maxn);
return ;
}

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

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

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

  2. Codeforces Round #344 (Div. 2) E. Product Sum 维护凸壳

    E. Product Sum 题目连接: http://www.codeforces.com/contest/631/problem/E Description Blake is the boss o ...

  3. Codeforces Round #344 (Div. 2) D. Messenger kmp

    D. Messenger 题目连接: http://www.codeforces.com/contest/631/problem/D Description Each employee of the ...

  4. Codeforces Round #344 (Div. 2) C. Report 其他

    C. Report 题目连接: http://www.codeforces.com/contest/631/problem/C Description Each month Blake gets th ...

  5. Codeforces Round #344 (Div. 2) B. Print Check 水题

    B. Print Check 题目连接: http://www.codeforces.com/contest/631/problem/B Description Kris works in a lar ...

  6. Codeforces Round #344 (Div. 2) A. Interview 水题

    A. Interview 题目连接: http://www.codeforces.com/contest/631/problem/A Description Blake is a CEO of a l ...

  7. Codeforces Round #344 (Div. 2) B. Print Check

    B. Print Check time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  8. Codeforces Round #344 (Div. 2)(按位或运算)

    Blake is a CEO of a large company called "Blake Technologies". He loves his company very m ...

  9. Codeforces Round #344 (Div. 2)

    水 A - Interview 注意是或不是异或 #include <bits/stdc++.h> int a[1005], b[1005]; int main() { int n; sc ...

随机推荐

  1. C++11 type_traits 之is_same源码分析

    请看源码: template<typename _Tp, _Tp __v> struct integral_constant { static const _Tp value = __v; ...

  2. 题解 CF682C 【Alyona and the Tree】

    简单搜索题,我们每找到一组不满足题目给出条件的点和边就将其整个子树删除,然后最终答案加上该子树的大小即可.注意,搜索的时候如果当前的边权和sum已经为负了,应该将其改为0(可以想想为什么) 注:题目翻 ...

  3. 【带 josn参数的测法】

    遇到json 参数的情况这样写  ,否则就会报错 cod 415   nocookie post请求 ,","email":"beihe@163.com&quo ...

  4. IMPI Python集群运行报错:

    Intel MPI环境利用hostfile多主机运行下报错 HYDU_process_mfile_token (../../utils/args/args.c:523): token slots no ...

  5. Bootstrap框架(组件)

    按钮组 通过按钮组容器把一组按钮放在同一行里.通过与按钮插件联合使用,可以设置为单选框或多选框的样式和行为. 按钮组中的工具提示和弹出框需要特别的设置 当为 .btn-group 中的元素应用工具提示 ...

  6. 【转】Expressions versus statements in JavaScript

    原文地址:http://www.2ality.com/2012/09/expressions-vs-statements.html Update 2012-09-21: New in Sect. 4: ...

  7. Python练习——循环2

    1.求1~100之间能被7整除,但不能同时被5整除的所有整数 . for i in range(1,101): if i%7 == 0 and i%5 !=0: print(i) 2.输出“水仙花数” ...

  8. 11.22Daily Scrum

    人员 任务分配完成情况 明天任务分配 王皓南 实现网页上视频浏览的功能.研究相关的代码和功能.979 数据库测试 申开亮 实现网页上视频浏览的功能.研究相关的代码和功能.978 实现视频浏览的功能 王 ...

  9. Java中I/O流之Object流

    Java 中的 object 流:直接将 Object 对象写入或读出 1. serializable 接口:序列化,可以被序列化的,若确实需要将某个类的对象写在硬盘上或网络上,想把他们序列化成一个字 ...

  10. LintCode-88.最近公共祖先

    最近公共祖先 给定一棵二叉树,找到两个节点的最近公共父节点(LCA). 最近公共祖先是两个节点的公共的祖先节点且具有最大深度. 注意事项 假设给出的两个节点都在树中存在 样例 对于下面这棵二叉树 LC ...