P9178 [COCI 2022/2023 #5] Diskurs

Description

You are given $n$ non-negative integers $a_1, a_2, \cdots a_n$, each of which is less than $2^m$. For each number, you need to find its maximum Hamming distance to the other elements in the array. The Hamming distance between two non-negative integers is defined as the number of positions where their binary representations differ (adding leading zeros if necessary). Formally, for each $i$, compute: $$\max\limits_{1\leq j\leq n} \operatorname{hamming}(a_i,a_j)$$

Input Format

The first line contains two integers $n$ and $m \ (1\leq n\leq 2^m,1\leq m\leq 20)$。 The second line contains $n$ numbers $a_i \ (0 \leq a_i < 2^m)$。

Output Format

Output one line with $n$ integers. The $i$-th integer represents the maximum Hamming distance between $a_i$ and the other elements in the array.

Explanation/Hint

| Subtask | $\text{pts}$ | Constraints | | :----------: | :----------: | :----------: | | $0$ | $0$ | Sample only | | $1$ | $20$ | $m\leq 10$ | | $2$ | $25$ | $m\leq 16$ | | $3$ | $25$ | None | Translated by ChatGPT 5