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, becausef(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 andr = 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.

题意:求[l,r]内ai的or和bi的or和的最大值;

思路:暴力求任意的l到r的要求值,再找出最大的输出;

AC代码:

#include <bits/stdc++.h>
using namespace std;
long long a[1003],b[1003],fa[1003][1003],fb[1003][1003];
int n;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=n;i++)
{
cin>>b[i];
}
long long x,y;
for(int i=1;i<=n;i++)
{
fa[i][i]=a[i];
fb[i][i]=b[i];
for(int j=i+1;j<=n;j++)
{
fa[i][j]=(fa[i][j-1]|a[j]);
fb[i][j]=(fb[i][j-1]|b[j]);
}
}
long long ans=0;
for(int i=1;i<=n;i++)
{
for(int j=i;j<=n;j++)
{
ans=max(ans,fa[i][j]+fb[i][j]);
}
}
cout<<ans<<"\n";
return 0;
}

codeforces 631A A. Interview的更多相关文章

  1. codeforces 631A Interview

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

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

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

  3. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  4. HPU周赛题目解析

    A - Wilbur and Swimming Pool Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  5. Codeforces--631A--Interview(位运算)

     Interview Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:262144KB     ...

  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. 【57.97%】【codeforces Round #380A】Interview with Oleg

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

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

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

  9. CodeForces 738A Interview with Oleg

    模拟. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #includ ...

随机推荐

  1. 滑动窗口计数java实现

    滑动窗口计数有很多使用场景,比如说限流防止系统雪崩.相比计数实现,滑动窗口实现会更加平滑,能自动消除毛刺. 概念上可以参考TCP的滑窗算法,可以看一下这篇文章(http://go12345.iteye ...

  2. shiro 实现自己定义权限规则校验

    <span style="font-family: Arial, Helvetica, sans-serif;">在系统中使用shiro进行权限管理,当用户訪问没有权限 ...

  3. 怎样去掉a标签的蓝框

    直接上代码 *{-webkit-tap-highlight-color:rgba(255,0,0,0);} 我是直接给每一个都加了这个属性   其实没有必要 因为 只有a 标签 input 标签 和t ...

  4. CAFFE学习笔记(一)Caffe_Example之训练mnist

    0.参考文献 [1]caffe官网<Training LeNet on MNIST with Caffe>; [2]薛开宇<读书笔记4学习搭建自己的网络MNIST在caffe上进行训 ...

  5. CMD命令获取电脑所有连接过的WiFi密码

    cmd中输入命令:for /f "skip=9 tokens=1,2 delims=:" %i in ('netsh wlan show profiles') do  @echo ...

  6. 九度OJ 1206:字符串连接 (字符串操作)

    时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:4127 解决:1957 题目描述: 不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来. 输入: 每一行包括两个 ...

  7. php, tp5, 选中导航菜单

    1. 首先定义一个函数: function nav_select($navindex){ $nav_arr = [ 1 => ['index',], 2 => ['mei',], 3 =& ...

  8. Python菜鸟之路:Python基础——函数

    一.函数 1. 简介 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段.函数能提高应用的模块性,和代码的重复利用率. 2. 组成 函数代码块以 def 关键词开头,后接函数名和圆括号( ...

  9. python基础-第五篇-5.2递归

    又是一个阳光明媚的日子,小白看着刚刚从东边升起的太阳,感觉太阳爷爷也在向她打招呼,小白就不经的微笑起来!心想:今天又会学到什么有趣的东西呢?有些小期待,也有些小激动! 小刘来得比小白还早,两辆相视而笑 ...

  10. git clone了整个远程仓库分支

    git之远程标签下载(远程分支) 一般我们发布一个新版本到线上服务器时都会在版本库中打一个标签,这样我们可以随时查看这个打标签的版本,就是说标签其实是版本库中一个快照.git的标签与分支类似,区别是分 ...