int ch[maxn][2], val[maxn], tot = 0; voidinsert(char* s){ int now = 0; for (int i = 0; s[i]; i++) { if (ch[now][s[i] - '0']) now = ch[now][s[i] - '0']; else now = ch[now][s[i] - '0'] = ++tot; } val[now]++; }
int ch[maxn * 30][2], val[maxn * 30], tot; voidinsert(char* s){ int now = 0; for (int i = 0; s[i]; i++) { if (ch[now][s[i] - '0']) now = ch[now][s[i] - '0']; else now = ch[now][s[i] - '0'] = ++tot; } val[now]++; } voidinsert(int x){ char tmp[35]; for (int i = 30; i >= 0; i--) { tmp[30 - i] = ((x >> i) & 1) + '0'; } tmp[31] = 0; // cout << tmp << endl; insert(tmp); } intget(char* s){ int x = 0; for (int i = 0; i <= 30; i++) { if (s[i] == '1') x += (1 << (30 - i)); } // cout << x << endl; return x; } intquery(int x){ char tmp[35]; for (int i = 30; i >= 0; i--) { tmp[30 - i] = ((x >> i) & 1) + '0'; } tmp[31] = 0; int now = 0, ans = 0; for (int i = 0; tmp[i]; i++) { if (tmp[i] == '1') { if (ch[now][0]) now = ch[now][0]; elseif (ch[now][1]) tmp[i] = '0', now = ch[now][1]; elsereturn ans; } else { if (ch[now][1]) tmp[i] = '1', now = ch[now][1]; elseif (ch[now][0]) now = ch[now][0]; elsereturn ans; } if (val[now]) ans = max(ans, get(tmp)); } return ans; }
int n, a[maxn];
intmain(){ scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", a + i); insert(a[i]); } int ans = 0; for (int i = 0; i < n; i++) { ans = max(ans, query(a[i])); } cout << ans << endl; return0; }