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. js 验证ip列表

    如题. <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title ...

  2. 函数导出在kvm_intel.ko,kvm.ko不共享

    KVM一共包含了三个内核模块,kvm_intel.ko,kvm_amd.ko,kvm.ko.其中两个重要文件x86.c和vmx.c在编译后分别会生成kvm_intel.ko和kvm.ko两个内核模块, ...

  3. python基础===flask使用整理(转)

    flask 使用的一些整理 资源 Flask 文档|英文| expore flask| 快速教材| flask-admin| Flask-DebugToolbar| Flask-Login| Flas ...

  4. 异步网络模块之aiohttp的使用(一)

    异步网络模块之aiohttp的使用(一) 平时我们也许用的更多的是requests模块,或者是requests_hml模块,但是他们都属于阻塞类型的不支持异步,速度很难提高,于是后来出现了异步的gre ...

  5. [How to]基于本地镜像的yum镜像源搭建

    1.简介 本文介绍如何在封闭环境(无外网)下安装离线安装本地镜像与基于本地镜像的yum镜像源. 2.环境版本交代: OS:CentOS-6.7-x86_64-minimal yum: yum-3.2. ...

  6. 如何消除类型是submit类型的按钮的默认文字 ‘确认提交’

    只需要加上value="" 即可.默认的文字就可以去掉了.

  7. leetcode 之Set Matrix Zeroes(10)

    设置两个布尔数组,记录行和列是否存在0.需要注意的是如何将行或列设为0. void setZeros(vector<vector<int>> &matrix) { in ...

  8. SRM 739 Div.2

    250 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostre ...

  9. linux命令(42):wc命令

    Linux系统中的wc(Word Count)命令的功能为统计指定文件中的字节数.字数.行数,并将统计结果显示输出. 1.命令格式: wc [选项]文件... 2.命令功能: 统计指定文件中的字节数. ...

  10. Largest Number——STL的深层理解

    Given a list of non negative integers, arrange them such that they form the largest number. For exam ...