P22412 [HackerRank] Manipulative numbers
提高-
题目描述

Suppose that $\mbox{A}$ is a list of $n$ numbers $\{A_1,A_2,A_3,\ldots,A_n\}$ and $B=\{B_1,B_2,B_3,\ldots,B_n\}$ is a permutation of these numbers, we say B is K-Manipulative if and only if:

$M(B)=minimum(B_1\oplus B_2,B_2\oplus B_3,B_3\oplus B_4,...,B_{n-1}\oplus B_n,B_n\oplus B_1)$ is not less than $2^{K}$, where $\theta$ represents the XOR operator.

You are given $\mbox{A}$. Find the largest $\mbox{K}$ such that there exists a K-manipulative permutation $\mbox{B}$.

Input:

The first line is an integer $N$. The second line contains $N$ space separated integers - $A_1\ A_2\ \cdots\ A_n$.

Output:

The largest possible $\mbox{K}$, or $-1$ if there is no solution.

Constraints:

$1<n<=100$
$0\leq A_i\leq10^9,where i\in[1,n]$

Sample Input 0
3
13 3 10

Sample Output 0
2

Explanation 0

Here the list $\mbox{A}$ is $\{13,3,10\}$. One possible permutation $B=\{10,3,13\}$. Here $M(B)=minimum\{B_1\oplus B_2,B_2\oplus B_3,B_3\oplus B_1\}=$

$\textit{minimum}\{10\oplus3,3\oplus13,13\oplus10\}=\textit{minimum}\{9,14,7\}=7$.

So there exists a permutation $\mbox{B}$ of $\mbox{A}$ such that $M(B)$ is not less than $4=2^2$. However there does not exist any permutation $\mbox{B}$ of $\mbox{A}$ such that $M(B)$ is not less than $8=2^3$. So the maximum possible value of $\mbox{K}$ is $2$.

Sample Input 1
4
1 2 3 4

Sample Output 1
1

Explanation 1

Here the list $\mbox{A}$ is $\{1,2,3,4\}$. One possible permutation $B=\{1,2,4,3\}$. Here $M(B)=minimum\{B_1\oplus B_2,B_2\oplus B_3,B_3\oplus B_4\:B_4\oplus B_1\}=$

$minimum\{1\oplus2,2\oplus4,4\oplus3\:3\oplus1\}=minimum\{3,6,7,2\}=2$.

So there exists a permutation $\mbox{B}$ of $\mbox{A}$ such that $M(B)$ is not less than $2=2^1$. However there does not exist any permutation $\mbox{B}$ of $\mbox{A}$ such that $M(B)$ is not less than $4=2^2$. So the maximum possible value of $\mbox{K}$ is $1$.

输入格式

见题面

输出格式

见题面

样例输入
3 13 3 10
样例输出
2