Comments

Just try out a few cases , you will realize your mistake

bro we need to find maximum absolute path sum

On --n--Good strings, 5 years ago
0

Actually it is an interview problem so no link available.

Auto comment: topic has been updated by --n-- (previous revision, new revision, compare).

is there any such relation for more than 2 numbers?

On TlatoaniCodeforces Global Round 10, 6 years ago
0

What is the logic behind it?

On TlatoaniCodeforces Global Round 10, 6 years ago
0

someone please explain problem C

On sshwyRCodeforces Round #664, 6 years ago
-37

include <bits/stdc++.h>

using namespace std;

define ll long long

int main() { ll n,m,ans=0; cin>>n>>m; ll A[n],B[m], dp[n][m]; for(int i=0;i<n;i++){ cin>>A[i]; } for(int i=0;i<m;i++){ cin>>B[i]; } ll smallest = 10000000000000; ll maxi = 0; for(int i=0;i<n;i++){ smallest = 10000000000000; for(int j=0;j<m;j++){ if( smallest > (A[i]&B[j]) ) smallest = (A[i]&B[j]); dp[i][j] = (A[i]&B[j]); } maxi = max(maxi,smallest); } ans = maxi; for(int i=0;i<n;i++){ smallest = 10000000000000; for(int j=0;j<m;j++){ if(smallest > (ans|dp[i][j]) ) smallest = (ans|dp[i][j]); } ans = smallest; } cout<<ans<<endl; return 0; }

Someone please explain the complete logic of the above program. I saw same thing in many accepted codes.

On sshwyRCodeforces Round #664, 6 years ago
0

Which test case?

On sshwyRCodeforces Round #664, 6 years ago
0

How can you say that answer will be atleast mx?

On sshwyRCodeforces Round #664, 6 years ago
-8

int main() { ios_base :: sync_with_stdio(false); cin.tie(NULL); auto startTime = curTime();

int n,m;
cin>>n>>m;

vi a(n);
vi b(m);
rep(i,n) cin>>a[i];
rep(i,m) cin>>b[i];

ll mx=0;
rep(i,n)
{
    ll mn = inf;
    rep(j,m)
    {
        mn = min(mn, a[i]&b[j]);
    }
    mx = max(mx,mn);
}
ll ans=0;
rep(i,n)
{
    ll mn = inf;
    rep(j,m)
    {
        mn = min(mn, mx|(a[i]&b[j]));
    }
    mx=mn;
    ans = max(ans,mn);
}

cout<<ans<<endl;

Can anyone explain the logic of this solution? I saw same thing in many accepted solutions.