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. js自己定义插件-选项卡

    该功能比較简单.巩固一下jquery插件写法,注意引入的jquery.js  . 自己定义插件路径代码例如以下: 页面: <!doctype html> <html> < ...

  2. 网络流合集:bzoj1433,1934,1854 题解

    转载请注明:http://blog.csdn.net/jiangshibiao/article/details/23992205 网络流/二分图大合集 [NO.1*原题] 1433: [ZJOI200 ...

  3. centos set up samba

    原文中文链接:https://wiki.centos.org/zh/HowTos/SetUpSamba 原文英文链接:https://wiki.centos.org/HowTos/SetUpSamba ...

  4. 从零开始写一个Exporter

    前言 上一篇文章中已经给大家整体的介绍了开源监控系统Prometheus,其中Exporter作为整个系统的Agent端,通过HTTP接口暴露需要监控的数据.那么如何将用户指标通过Exporter的形 ...

  5. java 基于tomcat的数据源案例

    1.在context中定义数据源 <?xml version="1.0" encoding="UTF-8"?> <Context path=& ...

  6. c++操作flash

    c++操作falsh,忘了原文在哪了,自己尝试了,直接贴代码 // SDK版本 //////////////////////////////////////////////////////////// ...

  7. centos6安装nginx最详细步骤

    第一步:在centos下面下载 nginx          wget http://nginx.org/download/nginx-1.2.9.tar.gz 解压 tar zxf nginx-1. ...

  8. 我的Android进阶之旅------>Android二级ListView列表的实现

    实现如下图所示的二级列表效果 首先是在布局文件中,布局两个ListView,代码如下: <LinearLayout xmlns:android="http://schemas.andr ...

  9. 网络端口的作用及分类(转发:http://blog.csdn.net/dream_1996/article/details/73481201)

    一.什么是端口? 在开始讲什么是端口(port)之前,我们先来聊一聊什么是 port 呢?常常在网络上听说『我的主机开了多少的 port ,会不会被入侵呀!?』或者是说『开那个 port 会比较安全? ...

  10. strstr使用

    extern char strstr(char str1, const char *str2); 语法: strstr(str1,str2) str1: 被查找目标 string expression ...