Password Creation
InterviewTime limit1sMemory limit1024 MB
Given N and a set of M used passwords, choose a password from 0 to N maximizing the minimum Hamming distance to any used password.
- Level
Medium6 of 10
- Topics
- Bit manipulation, Binary search, Greedy, Math
- Solved
- No attempts yet
Problem
Hyangbin works as a security officer in the computer lab at Sogang University. One day he receives an email. The email says that abnormal login attempts on the server administrator account have been detected, and the attached file contains the list of passwords used in the login attempts so far. The password for the server administrator account can be any integer from to .
The safety distance between two passwords is defined as the number of positions where the two passwords differ in binary representation. For example, in binary is and in binary is . They differ in positions, so the safety distance between and is .
The safety level of a password is defined as the minimum of its safety distances to every password used in the login attempts so far. For example, suppose the passwords used so far are and . For a new password , the safety distance between and is , and the safety distance between and is , so the safety level of is .
To delay the hacker from finding out the password as long as possible, Hyangbin wants to change the administrator account password currently in use so that its safety level is as high as possible. Find the safety level of the password with the highest safety level.
Input
The first line contains the integer , the maximum value of the administrator account password. ()
The second line contains the integer , the number of passwords used in the login attempts. ()
The third line contains the integers , the passwords used in the login attempts. ()
Output
Print the safety level of the password with the highest safety level.