6910.Hamming Distance

Time Limit: 1s Memory Limit: 512MB

The Hamming distance between two strings $a$ and $b$ of equal length is the number of positions where the strings differ.

You are given $n$ bit strings, each of length $k$ and your task is to calculate the minimum Hamming distance between two strings.

Input Format(From the terminal/stdin)

The first input line has two integers $n$ and $k$ : the number of bit strings and their length.

Then there are $n$ lines each consisting of one bit string of length $k$ .

  • $2 \le n \le 2 \cdot 10^4$
  • $1 \le k \le 30$

Output Format(To the terminal/stdout)

Print the minimum Hamming distance between two strings.

Sample Input

Copy
5 6
110111
001000
100001
101000
101110
 · \n
      \n
      \n
      \n
      \n
      \n

Sample Output

Copy
1
 \n

The strings 101000 and 001000 differ only at the first position.

Source: CSES, Advanced Techniques, 2136

Submit

请先 登录

© 2025 FAQs