首页 > 其他分享 >CodeForces - 631A Interview (思想)水

CodeForces - 631A Interview (思想)水

时间:2023-05-08 21:32:51浏览次数:47  
标签:integers 631A 22 int CodeForces value maximum Interview define

Time Limit: 1000MS

 

Memory Limit: 262144KB

 

64bit IO Format: %I64d & %I64u

CodeForces - 631A


Interview



Submit Status




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 sumf(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



51 2 4 3 22 3 3 12 1





Output



22





Input


1013 2 7 11 8 4 9 8 5 15 7 18 9 2 3 0 11 8 6




Output



46







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 first sample, one of the optimal answers is l = 2 and r = 4, because f(a, 2, 4) + f(b, 2, 4) = (2 OR 4OR 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.




Source



Codeforces Round #344 (Div. 2)



//题意:定义方程f(a,2,4)=a[2]|a[3]|a[4]。



先输入一个n,表示数组的长度,再输入a[],b[]。让求f(a,l,r)+f(b,l,r)。l表示数组的左端点,r表示数组的右端点。



//思路:



因为是或运算,所以不管几个数或运算(|),值只会变大,所以直接求出所有a[i]的取或(|)的值再加上所有b[i]的取或(|)的值即可。




#include<stdio.h>
#include<string.h>
#include<algorithm>
#define INF 0x3f3f3f3f
#define ll long long
#define N 1010
#define M 1000000007
#define PI acos(-1.0)
using namespace std;
int a[N];
int b[N];
int main()
{
	int i,j,k;
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int aa=0,bb=0;
		for(i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
			aa=aa|a[i];
		}
		for(i=0;i<n;i++)
		{
			scanf("%d",&b[i]);
			bb=bb|b[i];
		}
		printf("%d\n",aa+bb);
	}
	return 0;
}





标签:integers,631A,22,int,CodeForces,value,maximum,Interview,define
From: https://blog.51cto.com/u_16079508/6256249

相关文章

  • CodeForces - 630F Selection of Personnel (组合数学)
    TimeLimit: 500MS MemoryLimit: 65536KB 64bitIOFormat: %I64d&%I64uCodeForces-630FSelectionofPersonnelSubmit StatusDescriptionOnecompanyofITCitydecidedtocreateagroupofinnovativedevelopmentsconsistingfrom 5 to 7 peopleandhir......
  • CodeForces - 621B Wet Shark and Bishops (数学几何&技巧)
    TimeLimit: 2000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uCodeForces-621BWetSharkandBishopsSubmit StatusDescriptionToday,WetSharkisgiven n bishopsona 1000 by 1000 grid.Bothrowsandcolumnsofthegridarenumberedfro......
  • CodeForces - 618A Slime Combining (快速幂)
    CodeForces-618ASlimeCombiningTimeLimit: 2000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uSubmit StatusDescriptionYourfriendrecentlygaveyousomeslimesforyourbirthday.Youhave n slimesallinitiallywithvalue 1.Youare......
  • CodeForces - 626B Cards (全排列&模拟)
    TimeLimit: 2000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uCodeForces-626BCardsSubmit StatusDescriptionCatherinehasadeckof ntakeanytwo(notnecessarilyadjacent)cardswithdifferentcolorsandexchangethemforanewcardof......
  • CodeForces - 597A Divisibility (模拟)
    TimeLimit: 1000MS MemoryLimit: 262144KB 64bitIOFormat: %I64d&%I64uCodeForces-597ADivisibilitySubmit StatusDescriptionFindthenumberof k-divisiblenumbersonthesegment [a, b].Inotherwordsyouneedtofindthenumberofsuchintegerv......
  • Codeforces Round 871 (Div. 4)
    A.LoveStory#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongintread(){intx=0,f=1,ch=getchar();while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();if......
  • Codeforces Round 871 (Div. 4)
    A.LoveStory题意:给定n个长度为10的字符串,问其与codeforces字符串的对应下标字母不同的个数。分析:对于每个字符串从前往后依次和“codeforces”对应字符比较然后统计不同字母数即可code:#include<bits/stdc++.h>usingnamespacestd;intmain(){ std::ios::sync_wit......
  • Codeforces Round 871 (Div. 4)
    CodeforcesRound871(Div.4)A-LoveStory#include<bits/stdc++.h>usingnamespacestd;typedefpair<int,int>PII;typedefpair<string,int>PSI;constintN=1e5+5,INF=0x3f3f3f3f,Mod=1e6;constdoubleeps=1e-6;typedeflonglongll;i......
  • Codeforces 871 div4(重拳出击)
    Codeforces871div4ABC简单题D题意每次操作可以将当前的数分成两份,一份是\(\frac{1}{3}\),一份是\(\frac{2}{3}\),问当前数n可否进行若干次操作,最终出现一份大小为m的片。递归一下就好了,数据最大才\(10^7\)代码voiddfs(intx){ if(x==m){flag=1;return;} if(flag)re......
  • Codeforces Round 870 (Div. 2)
    CodeforcesRound870(Div.2)A-TrustNobody思路:枚举每一种说谎人数x,若a[i]大于x则说谎人数加一,判断最后说谎总人数是否为x,若是则输出x,结束枚举;若没有满足的x则-1#include<bits/stdc++.h>usingnamespacestd;typedefpair<int,int>PII;typedefpair<string,int>PSI;......