Interview

Crawling in process...
Crawling failed
Time Limit:1000MS    
Memory Limit:262144KB    
64bit IO Format:
%I64d & %I64u

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

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

Sample Output

Hint

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

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
__int64 num1[1010],num2[1010];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(num1,0,sizeof(num1));
memset(num2,0,sizeof(num2));
for(int i=1;i<=n;i++)
{
cin>>num1[i];
if(i>1) num1[1]|=num1[i];
} for(int i=1;i<=n;i++)
{
cin>>num2[i];
if(i>1) num2[1]|=num2[i];
}
cout<<num1[1]+num2[1]<<endl;
}
return 0;
}

Codeforces--631A--Interview(位运算)的更多相关文章

  1. CodeForces 282C(位运算)

    C. XOR and OR time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  2. codeforces 631A Interview

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

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

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

  4. Codeforces 868D Huge Strings - 位运算 - 暴力

    You are given n strings s1, s2, ..., sn consisting of characters 0 and 1. m operations are performed ...

  5. 图论/位运算 Codeforces Round #285 (Div. 2) C. Misha and Forest

    题目传送门 /* 题意:给出无向无环图,每一个点的度数和相邻点的异或和(a^b^c^....) 图论/位运算:其实这题很简单.类似拓扑排序,先把度数为1的先入对,每一次少一个度数 关键在于更新异或和, ...

  6. Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维

    & -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...

  7. Divide by Zero 2021 and Codeforces Round #714 (Div. 2) B. AND Sequences思维,位运算 难度1400

    题目链接: Problem - B - Codeforces 题目 Example input 4 3 1 1 1 5 1 2 3 4 5 5 0 2 0 3 0 4 1 3 5 1 output 6 ...

  8. Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] A. Raising Bacteria【位运算/二进制拆分/细胞繁殖,每天倍增】

    A. Raising Bacteria time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #443 (Div. 2) C 位运算

    C. Short Program time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  10. Codeforces 620E New Year Tree(线段树+位运算)

    题目链接 New Year Tree 考虑到$ck <= 60$,那么用位运算统计颜色种数 对于每个点,重新标号并算出他对应的进和出的时间,然后区间更新+查询. 用线段树来维护. #includ ...

随机推荐

  1. Java线程处理

    Java线程处理 创建线程 继承Thread类 public class TestThread extends Thread{ public void run(){ System.out.printl ...

  2. 重启rsyncd

    systemctl  restart  rsyncd.service

  3. 【原】Python学习

    1.常用模块介绍 #python -m SimpleHTTPServer 执行上面的命令就会在服务器当前目录下启动一个文件下载服务器,默认打开8000端口.这个时候,你只需要将IP和端口告诉客户端,即 ...

  4. P1223 排队接水

    题目描述 有n个人在一个水龙头前排队接水,假如每个人接水的时间为Ti,请编程找出这n个人排队的一种顺序,使得n个人的平均等待时间最小. 输入输出格式 输入格式: 输入文件共两行,第一行为n:第二行分别 ...

  5. Python学习-字符串函数操作1

    字符串的函数操作 capitalize():可以将字符串首字母变为大写 返回值:首字符大写后的新字符串 str = "liu" print(str.capitalize()); / ...

  6. Oracle 数据库启动与关闭 各种方式详解整理

    概述 只有具备sysdba和sysoper系统特权的用户才能启动和关闭数据库. 在启动数据库之前应该启动监听程序,否则就不能利用命令方式来管理数据库,包括启动和关闭数据库. 虽然数据库正常运行,但如果 ...

  7. Literature Review on Tidal Turbine

    source: scopus , SCIE keywords in tilte: tidal turbine Software: Bibliometrix

  8. 爬楼梯,N级楼梯有多少种走法?

    https://blog.csdn.net/tcpipstack/article/details/45173685 一个人爬楼梯,一步可以迈一级,二级,三级台阶,如果楼梯有N级,要求编写程序,求总共有 ...

  9. 【12】AngularJS 事件

    AngularJS 事件 AngularJS 有自己的 HTML 事件指令. ng-click 指令 ng-click 指令定义了 AngularJS 点击事件. <div ng-app=&qu ...

  10. 【Codeforces 582A】GCD Table

    [链接] 我是链接,点我呀:) [题意] 给你一个数组A[]经过a[i][j] = gcd(A[i],A[j])的规则生成的二维数组 让你求出原数组A [题解] 我们假设原数组是A 然后让A数组满足A ...