Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
139902 陈家宝 Chip Factory C++ 通过 100 818 MS 484 KB 1470 2024-03-26 16:43:43

Tests(10/10):


#include<bits/stdc++.h> using namespace std; const int logw = 32; struct node { int son[2],vis, num; node(int son1 = 0, int son2 = 0, int vis = 0, int num = 0) : son {son1, son2}, vis(vis), num(num) {} }; vector<node> t(1); #define int long long inline int read() { int x=0; char c=getchar(); for(; c<'0' || c>'9'; c=getchar()); for(; c<='9' && c>='0'; c=getchar())x=(x<<3)+(x<<1)+c-'0'; return x; } void add(int x) { t[0].vis++; int p = 0; for (int i = logw; i >= 0; i--) { bool wz = (x >> i) & 1; if (!t[p].son[wz]) t.push_back({}), t[p].son[wz] = t.size() - 1; p = t[p].son[wz]; t[p].vis++; } t[p].num = x; } void del(int x) { t[0].vis--; int p = 0; for (int i = logw; i >= 0; i--) { bool wz = (x >> i) & 1; p = t[p].son[wz]; if (p)t[p].vis--; } } int solve(int x) { int p = 0; for (int i = logw; i >= 0; i--) { bool wz = (x >> i) & 1; if (t[p].son[!wz] && t[t[p].son[!wz]].vis)p = t[p].son[!wz]; else p = t[p].son[wz]; } return t[p].num; } int q, n, a[1005]; signed main(){ q = read(); while (q--) { int ans = -1; t.assign(1, {0,0,0,0}); n = read(); for (int i = 1; i <= n; i++) { a[i] = read(); add(a[i]); } for (int i = 1; i <= n; i++) for (int j = i + 1; j <= n; j++) { del(a[i]); del(a[j]); ans = max(ans, (a[i] + a[j]) ^ solve(a[i] + a[j])); add(a[i]); add(a[j]); } printf("%lld\n", ans); } return 0; }


测评信息: