Hey, Can anybody tells why this bruteforce not working.
link to qs: Problem - C - Codeforces.
my sol :
#include <bits/stdc++.h>
using namespace std;
#define int long long
int dp[201];
const int mx = 1e9;
int solve(int *arr, int *brr, int index, int n, int m)
{
if (index >= n)
return 0;
if (dp[index] != -1)
return dp[index];
int res = mx * mx;
for (int j = 0; j < m; j++)
{
int temp = (arr[index] & brr[j]);
temp |= solve(arr, brr, index + 1, n, m);
res = min(res, temp);
}
return dp[index] = res;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
int arr[n], brr[m];
for (int i = 0; i < n; i++)
cin >> arr[i];
for (int j = 0; j < m; j++)
cin >> brr[j];
memset(dp, -1, sizeof(dp));
cout << solve(arr, brr, 0, n, m);
return 0;
}