公式

E - Split and Square 解説 by evima


Below, we see the integers less than \(2^{M}\) and bitwise XOR \(\oplus\) as the elements and addition in the vector space \(\mathbb{F}^M_{2}\), and use the terms in linear algebra.

[1] The change in the number of bases

Let \(e_1,\ e_2,\ \dots,\ e_n\ (e_i \in S)\) be the bases of the subspace spanned by the elements of \(S\). After an operation that divides the bases into \(\{e_1,\ e_2,\ \dots,\ e_m\} \subset T_1\) and \(\{e_{m+1},\ e_{m+2},\ \dots,\ e_{n}\} \subset T_2\), it will hold that \(\{e_1 \oplus e_2,\ e_1 \oplus e_3,\ \dots,\ e_1 \oplus e_m,\ e_{m+1} \oplus e_{m+2},\ e_{m+1} \oplus e_{m+3},\ \dots,\ e_{m+1} \oplus e_{n} \} \subset S\). These elements are linearly dependent, so \(S\) will have at least \(n-2\) bases.

How to reduce the number of bases? For instance, consider this case: let us represent every element of \(S\) as a linear combination of \(e_i\), and put to \(T_1\) all elements whose representation uses \(e_1\), and to \(T_2\) the rest. After this operation, every element of \(S\) will be representable as a linear combination of \(e_i\) without using \(e_1\), so there are at most \(n-1\) bases.

[2] When can we decrease it by \(2\)?

We have seen how to decrease the number of bases by at least \(1\). What remains is to see when it can be decreased by \(2\).

Assume that the operation is performed by dividing the bases into \(\{e_1,\ e_2,\ \dots,\ e_m\} \subset T_1\) and \(\{e_{m+1},\ e_{m+2},\ \dots,\ e_{n}\} \subset T_2\). To get \(n-2\) bases, every element of \(S\) after the operation must be representable by a linear combination of \(e_1 \oplus e_i\ (2 \leq i \leq m)\) and \(e_{m+1} \oplus e_j\ (m+2 \leq j \leq n)\). This is equivalent to being representable as a linear combination of \(e_i\) using:

  • an even number of elements from \(e_1,\ e_2,\ \dots,\ e_m\), and
  • an even number of elements from \(e_{m+1},\ e_{m+2},\ \dots,\ e_n\).

Based on this, let us consider how we should allocate the elements of \(S\) to \(T_1\) and \(T_2\). We have \(e_1 \in T_1\), so an element to assign to \(T_1\) must be representable as a linear combination of \(e_i\) using:

  • an odd number of elements from \(e_1,\ e_2,\ \dots,\ e_m\), and
  • an even number of elements from \(e_{m+1},\ e_{m+2},\ \dots,\ e_n\),

and vice versa for an element to assign to \(T_2\).

Thus, the number of bases can be reduced by \(2\) if and only if every element of \(S\) is representable as a linear combination of \(e_i\) using an odd number of them. Particularly, \(0 \in S\) always holds after one operation, so this can be done only in the first operation.

[3] Summary

Therefore, if there are \(n\) bases initially, the answer is \(n\) if \(n \leq 1\) or the condition in [2] is not satisfied, and \(n-1\) otherwise.

One can find the bases and check if the condition holds in \(O(NM^2)\) time by the sweeping-out method, which is fast enough.

投稿日時:
最終更新: