Chef and Pie
All submissions for this problem are available.
Chef loves to cook pies. But more than that, he loves to play with numbers. And this task is one of his favorites. The goal is very simple: you need to select 3 numbers from an array of N numbers, such that their XOR will be maximal.
XOR - exclusive or (xor - in Pascal, ^ - in C++)
The first line of input contains an integer T denoting the number of test cases. The first line of each test case contains a positive integer N denoting the number of integers in the given array. The second line contains N space-separated integers A1, A2, ..., AN containing the elements of the array.
For each test case, output a single line containing the maximal XOR of 3 chosen numbers in the array. Note, that you have to choose exactly 3 numbers.
- 1 ≤ T ≤ 3
- 3 ≤ N ≤ 2000
- 1 ≤ Ai ≤ 109
Input: 2 3 1 2 3 3 2 2 3 Output: 0 3
Subtask 1 (15 points): 3 ≤ N ≤ 100
Subtask 2 (10 points): 1 ≤ Ai ≤ 50
Subtask 3 (75 points): Look at constraints.
|Tags||bitwise-operatn, easy, furko, greedychxorr, ltime04|
|Time Limit:||1.5 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.