Untitled
raw download clone
TEXT
views 105
,
size 1785 b
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e5 + 5;
const int MOD = 1e9 + 7;
long long n, b[N], a[N];
pair<long long, long long> dp[N][2];

pair<ll, ll> go(ll i, ll which){
    if(i == n)
        return (which == 1 ? make_pair(b[i], 0ll) : make_pair(a[i], 0ll));
    if(dp[i][which].first != -1 and dp[i][which].second != -1)
        return dp[i][which];
    pair<ll, ll> ans = go(i + 1, 0);
    ans.first = (ans.first & (which == 0 ? a[i] : b[i]));
    pair<ll, ll> ans1 = go(i + 1, 1);
    ans1.first = (ans1.first & (which == 0 ? a[i] : b[i]));
    ans1.second++;
    if(ans.first > ans1.first)
        return dp[i][which] = ans;
    else if(ans1.first > ans.first)
        return dp[i][which] = ans1;
    else{
        if(ans.second < ans1.second)
            return dp[i][which] = ans;
        return dp[i][which] = ans1;
    }
}

void solve(){
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        dp[i][0].first = dp[i][1].first = dp[i][0].second = dp[i][1].second = -1;
    }
    for(int i = 1; i <= n; ++i)
        cin >> b[i];
    pair<ll, ll> ans = go(1, 0);
    pair<ll, ll> ans1 = go(1, 1);
    ans1.second++;
    if(ans.first > ans1.first)
        cout << ans.first << " " << ans.second << "\n";
    else if(ans1.first > ans.first)
        cout << ans1.first << " " << ans1.second << "\n";
    else if(ans.second < ans1.second)
        cout << ans.first << " " << ans.second << "\n";
    else
        cout << ans1.first << " " << ans1.second << "\n";
}

int main(){
    fast;
    int t = 1;
    cin >> t;
    while(t--)
        solve();
    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.