Codeforces Round #344 (Div. 2) A. Interview

时间:2023-03-08 19:14:33
//http://codeforces.com/contest/631/problem/A
package codeforces344; import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer; /**
* Created by lenovo on 2016-03-10.
*/
public class A344 {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof; void solve() throws IOException {
int n = nextInt();
int[] a = new int[1000 + 10];
int[] b = new int[1000 + 10];
for(int i = 0; i < n; ++i) {
a[i] = nextInt();
}
for(int i = 0; i < n; ++i) {
b[i] = nextInt();
} long max = -1;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j){
max = Math.max(max, f(a, b, i, j));
}
}
System.out.println(max);
} long f(int[] a, int[] b, int i, int j) {
int va = a[i];
int vb = b[i];
for(int ii = i; ii <= j; ++ii){
va = va | a[ii];
vb = vb | b[ii];
}
//System.out.println("va + vb " + va + vb);
return va + vb;
} A344() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
br.close();
}
public static void main(String[] args) throws IOException{
new A344();
}
String nextToken(){
while(st == null || !st.hasMoreTokens()){
try{
st = new StringTokenizer(br.readLine());
} catch(IOException e) {
eof = true;
return null;
}
}
return st.nextToken();
} String nextString(){
try{
return br.readLine();
} catch (Exception e) {
eof = true;
return null;
}
} int nextInt() throws IOException {
return Integer.parseInt(nextToken());
} long nextLong() throws IOException {
return Long.parseLong(nextToken());
} double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
}

  

水题异常的好刷 T_T