【Codeforces 631 A Interview】
来源:互联网 发布:客户统计系统php 编辑:程序博客网 时间:2024/06/18 18:50
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.
从 a 和 b 数组里分别选取一段进行或运算~很容易想到~或运算是递增的一个运算~直接对数组里的全部数进行或运算即为优解~
AC代码:
#include<cstdio>typedef long long LL;int main(){ int N; while(scanf("%d",&N) != EOF){ LL sum1 = 0,sum2 = 0,a; for(int i = 1 ; i <= N; i++){ scanf("%lld",&a); sum1 |= a; } for(int i = 1 ; i <= N; i++){ scanf("%d",&a); sum2 |= a; } printf("%lld\n",sum1 + sum2); } return 0;}
- CodeForces 631A-Interview
- Codeforces 631A - Interview
- CodeForces 631A--Interview
- CodeForces 631A Interview
- 【Codeforces 631 A Interview】
- codeforces 631A Interview
- Codeforces 631A Interview 【水题】
- CodeForces 631A 631A - Interview
- CodeForces 631 A A. Interview【枚举】
- Codeforces 631A Interview【模拟水题】
- Codeforces--631A--Interview(位运算)
- CodeForces - 631A Interview (思想)水
- CodeForces 631A:Interview【位运算】
- CodeForces 631A Interview(水题)
- CodeForces 631 A.Interview(水~)
- Codeforces Round #344 (Div. 2) 631A Interview (DP)
- Codeforces 631A Interview(分析&&位运算| )
- Codeforces Round #380A - Interview with Oleg
- leetcode_20. Valid Parentheses 括号匹配问题;java String实例的声明和初始化;没用栈;
- 搭建DevStack中遇到的问题及解决办法
- Retrofit谷歌官方详解
- 进程间通信基本概念
- 分享一个程序猿在流程数据查看权限问题的总结
- 【Codeforces 631 A Interview】
- vsftpd登录报530
- 此图片来自微信公众平台未经允许不可引用
- 搞了一个星期的扫码收款, 总结感悟
- Python串口编程
- 如何快速学会单片机编程并应用?
- gulp实现前端静态资源的压缩,加MD5戳,替换引用,加CDN前缀
- input type = button 中onclick无效
- 使用Akka的远程调用