Untitled
unknown
plain_text
a year ago
1.1 kB
5
Indexable
#include <bits/stdc++.h>
#define F first
#define S second
#define el cout << '\n'
#define maxn 100005
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define For(i,a,b) for ( int i = a; i <= b; i++)
using namespace std;
int n, child[maxn][2], cnt = 0, a[maxn];
void ThemVaoTrie(int s)
{
int u = 0;
for(int i = 30; i >= 0; i--)
{
int c = (s >> i) & 1;
if (child[u][c] == 0) {cnt++; child[u][c] = cnt; }
u = child[u][c];
}
}
int solve(int x)
{
int u = 0; int res = 0;
for(int i = 30; i >= 0; i--)
{
int c = (x >> i) & 1;
if (child[u][c ^ 1] != -1)
{
res += (1LL << i);
u = child[u][c ^ 1];
}
else u = child[u][c];
}
return res;
}
int main()
{
faster
cin >> n;
memset(child, -1, sizeof child);
int ans = -1;
For(i,1,n)
{
cin >> a[i];
ThemVaoTrie(a[i]);
}
For(i,1,n)
{
ans = max(ans, solve(a[i]));
}
cout << ans;
}
Editor is loading...
Leave a Comment