题解!!!!!
2025-10-01 09:48:14
发布于:浙江
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
const int N = 1000 + 10;
const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;
int a[maxn], b[maxn];
ll c0[3][30], c1[3][30];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
freopen("math.in", "r", stdin);
freopen("math.out", "w", stdout);
int n, x;
cin >> n >> x;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
cin >> b[i];
for (int i = 1; i <= n; i++)
{
for (int j = 25; j >= 0; j--)
{
if ((a[i] >> j) & 1)
c1[b[i]][j];
else
c0[b[i]][j];
}
}
ll ans = 0;
for (int i = 0; i <= x; i++)
{
ll res = 0;
for (int j = 25; j >= 0; j--)
{
if ((i >> j) & 1)
{
res += c1[0][j] * (1 << j) + (c1[1][j] + c0[1][j]) * (1 << j) + c0[2][j] * (1 << j);
}
else
{
res += c1[1][j] * (1 << j) + c1[2][j] * (1 << j);
}
}
ans = max(ans, res);
}
cout << ans << endl;
cout.flush();
fclose(stdin);
fclose(stdout);
return 0;
}
这里空空如也



有帮助,赞一个