比赛 |
4043级NOIP2022欢乐赛3rd |
评测结果 |
AAAAAAATTT |
题目名称 |
界外科学 |
最终得分 |
70 |
用户昵称 |
HeSn |
运行时间 |
4.226 s |
代码语言 |
C++ |
内存使用 |
32.12 MiB |
提交时间 |
2022-11-04 22:15:45 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n, m, half, a[50], b[50], num1[1 << 21], num2[1 << 21], cnt1, cnt2, ans;
map<int, int> mp, mp2;
int dfs2(int x, int s, int p) {
if(x == n + 1) {
if(!mp2[p]) {
num2[++ cnt2] = p;
}
if(s > mp2[p]) {
mp2[p] = s;
}
return 0;
}
dfs2(x + 1, s, p);
dfs2(x + 1, s + b[x], p ^ a[x]);
}
int dfs(int x, int s, int p) {
if(x == half + 1) {
if(!mp[p]) {
num1[++ cnt1] = p;
}
if(s > mp[p]) {
mp[p] = s;
}
return 0;
}
dfs(x + 1, s, p);
dfs(x + 1, s + b[x], p ^ a[x]);
return 0;
}
signed main() {
freopen("outsci.in", "r", stdin);
freopen("outsci.out", "w", stdout);
cin >> n >> m;
half = n / 2;
for(int i = 1; i <= n; i ++) {
cin >> a[i];
}
for(int i = 1; i <= n; i ++) {
cin >> b[i];
}
dfs(1, 0, 0);
// for(int i = 1; i <= cnt; i ++) {
// cout << c[i] << ' ' << mp[c[i]] << endl;
// }
dfs2(half + 1, 0, 0);
for(int i = 1; i <= cnt1; i ++) {
for(int j = 1; j <= cnt2; j ++) {
if((num1[i] ^ num2[j]) <= m) {
ans = max(ans, mp[num1[i]] + mp2[num2[j]]);
}
}
}
cout << ans << endl;
return 0;
}