"Codeforces" 631A interview

Source: Internet
Author: User



Http://codeforces.com/problemset/problem/631/A






Give two sets of arrays of the same length a0~n-1 b0~n-1 to find the maximum value of a continuous element in a bitwise OR (or) and the maximum value of a continuous element in B or (or)



Or operation of the words encountered a new number only add or unchanged, will not be reduced, so directly put all the number of bits or, then sum can be





#include<bits/stdc++.h>
using namespace std;

int n;
vector<int> a;
vector<int> b;

int main(){
    while(~scanf("%d", &n)){
        a.clear();
        b.clear();
        for(int i = 0; i < n; i++){
            int temp;
            scanf("%d", &temp);
            a.push_back(temp);
        }
        for(int i = 0; i < n; i++){
            int temp;
            scanf("%d", &temp);
            b.push_back(temp);
        }
        vector<int>::iterator it;
        int ans1 = 0;
        for(it = a.begin(); it != a.end(); it++){
            ans1 = ans1|(*it);
        }
        int ans2 = 0;
        for(it = b.begin(); it != b.end(); it++){
            ans2 = ans2|(*it);
        }
        int ans = ans1+ans2;
        printf("%d\n", ans);
    }
    return 0;
}
 





"Codeforces" 631A interview


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.