Codeforces Round #344 (Div. 2) A
1 second
256 megabytes
standard input
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.
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).
Print a single integer — the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.
5
1 2 4 3 2
2 3 3 12 1
22
10
13 2 7 11 8 4 9 8 5 1
5 7 18 9 2 3 0 11 8 6
46
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.
题解: max(f(a,l,r)+f((b,l,r)) f() 为求 l-->r的按位或的值
马上codeforces 上分
#include<bits/stdc++.h>
using namespace std;
int a[][];
int b[][];
int exm1[],exm2[];
int main()
{
int n;
int sum1=,sum2=,maxn=;;
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&exm1[i]);
}
for(int i=; i<=n; i++)
{
scanf("%d",&exm2[i]);
}
for(int i=; i<=n; i++)
{
sum1=exm1[i];
a[i][i]=sum1;
for(int j=i+; j<=n; j++)
{
a[i][j]=sum1|exm1[j];
sum1=a[i][j];
}
}
for(int i=; i<=n; i++)
{
sum2=exm2[i];
b[i][i]=sum2;
if(b[i][i]+a[i][i]>maxn)
maxn=b[i][i]+a[i][i];
for(int j=i+; j<=n; j++)
{
b[i][j]=sum2|exm2[j];
sum2=b[i][j];
if(b[i][j]+a[i][j]>maxn)
maxn=b[i][j]+a[i][j];
}
}
printf("%d\n",maxn);
return ;
}
Codeforces Round #344 (Div. 2) A的更多相关文章
- Codeforces Round #344 (Div. 2) A. Interview
//http://codeforces.com/contest/631/problem/Apackage codeforces344; import java.io.BufferedReader; i ...
- Codeforces Round #344 (Div. 2) E. Product Sum 维护凸壳
E. Product Sum 题目连接: http://www.codeforces.com/contest/631/problem/E Description Blake is the boss o ...
- Codeforces Round #344 (Div. 2) D. Messenger kmp
D. Messenger 题目连接: http://www.codeforces.com/contest/631/problem/D Description Each employee of the ...
- Codeforces Round #344 (Div. 2) C. Report 其他
C. Report 题目连接: http://www.codeforces.com/contest/631/problem/C Description Each month Blake gets th ...
- Codeforces Round #344 (Div. 2) B. Print Check 水题
B. Print Check 题目连接: http://www.codeforces.com/contest/631/problem/B Description Kris works in a lar ...
- 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 ...
- Codeforces Round #344 (Div. 2) B. Print Check
B. Print Check time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Codeforces Round #344 (Div. 2)(按位或运算)
Blake is a CEO of a large company called "Blake Technologies". He loves his company very m ...
- Codeforces Round #344 (Div. 2)
水 A - Interview 注意是或不是异或 #include <bits/stdc++.h> int a[1005], b[1005]; int main() { int n; sc ...
随机推荐
- Vue 兄弟组件通信(不使用Vuex)
Vue 兄弟组件通信(不使用Vuex) 项目中,我们经常会遇到兄弟组件通信的情况.在大型项目中我们可以通过引入vuex轻松管理各组件之间通信问题,但在一些小型的项目中,我们就没有必要去引入vuex.下 ...
- struts2源码分析-初始化流程
这一篇文章主要是记录struts.xml的初始化,还原struts2.xml的初始化流程.源码依据struts2-2.3.16.3版本. struts2初始化入口,位于web.xml中: <fi ...
- UVALive 3668 A Funny Stone Game(博弈)
Description The funny stone game is coming. There are n piles of stones, numbered with 0, 1, 2,..., ...
- Alpha-1
前言 失心疯病源1 团队代码管理github 站立会议 队名:PMS 530雨勤(组长) 今天完成了那些任务 10:00~13:00 OpenCV环境配置,Matlab工具包下载 15:40~17:1 ...
- <Android>tab选项卡
1.继承TabActivity实现 a) 在布局文件中使用FrameLayout列出Tab组件及Tab中的内容组件 b) Activity要继承TabActivity c ...
- C#控件DropDownList下拉列表默认打开
c#中的控件DropDownList要实现默打开确实不容易,之前也是想过页面上的点击之后就打开了,那直接模拟点击不就行了,试过后大失所望,根本没有效果. 于是网上找到了一个例子能实现IE浏览器下的打开 ...
- Chrome 的扩展功能
chrome浏览器修改cookie edit this cookie chrome插件是一款专为谷歌内核浏览器打造的cookie插件,安装谷歌浏览器edit this cookie插件后你就可以在浏览 ...
- Spyder5 & 显示器校准 & 色彩校准
Spyder5 & 显示器校准 & 色彩校准 Spyder5EXPRESS 绿蜘蛛5 – 轻松.快速地校准您的屏幕. Spyder5PRO 蓝蜘蛛5 – 可为您的所有笔记本电脑和台式机 ...
- [STL] map,multimap,unordered_map基本用法
map的特性是,所有元素都会根据元素的键值自动被排序.map的所有元素都是pair,同时拥有键值(key)和实值(value).pair的第一元素被视为键值,第二元素被视为实值.map不允许两个元素拥 ...
- TDDL剖析
前言 在开始讲解淘宝的TDDL(Taobao Distribute Data Layer)技术之前,请允许笔者先吐槽一番.首先要开喷的是淘宝的社区支持做的无比的烂,TaoCode开源社区上面,几乎从来 ...