Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
33890 Ender Chip Factory C++ 解答错误 0 25 MS 23692 KB 1771 2021-12-08 14:03:38

Tests(0/10):


#include <iostream> #include <cstdio> #include <cstring> using namespace std; struct Node { int son[2],vis; }t[2000010]; long long a[1010]; int pos = 1; inline long long read() { int s=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; } inline void write(long long x) { if(x<0){ putchar('-'); x=-x; } if(x>9) write(x/10); putchar(x%10+'0'); } void Add(long long x) { int p = 1,i; t[p].vis++; for(i = 63;i >= 0;i--) { long long b = (x>>i)&1; if(!t[t[p].son[b]].vis) t[p].son[b] = ++pos; p = t[p].son[b]; t[p].vis++; } return; } void Del(long long x) { int p = 1,i; t[p].vis--; for(i = 63;i >= 0;i--) { long long b = (x>>i)&1; t[t[p].son[b]].vis--; p = t[p].son[b]; } return; } long long Query(long long x) { long long ans = 0,p = 1,i; for(i = 63;i >= 0;i--) { long long b = (x>>i)&1ll; if(t[t[p].son[!b]].vis) { ans = (ans<<1) + !b; p = t[p].son[!b]; } else { p = t[p].son[b]; ans = (ans<<1) + b; } } return ans ^ x; } int main() { //freopen("chip.in","r",stdin); //freopen("chip.out","w",stdout); int T,lhn; T = read(); for(lhn = 1;lhn <= T;lhn++) { int n,i,j; long long ans = 0; memset(t,0,sizeof(t)); pos = 1; n = read(); for(i = 1;i <= n;i++) { a[i] = read(); Add(a[i]); } for(i = 1;i <= n;i++) { for(j = i + 1;j <= n;j++) { long long sum = a[i] + a[j]; Del(a[i]); Del(a[j]); ans = max(ans,Query(sum)); Add(a[i]); Add(a[j]); } } write(ans); } return 0; }


测评信息: