Official

B - Three Mex Editorial by evima


$X$ must contain $0, 1, 2, \cdots, A - 1$, and $Y$ must contain $0, 1, 2, \cdots, B - 1$. Therefore, when $X = \{0, 1, 2, \cdots, A - 1\}, Y = \{ 0, 1, 2, \cdots, B - 1 \}$, there must not exist $x \in X, y \in Y$ such that $x \oplus y = C$.

Also, if this condition is satisfied, a construction is always possible. We can add integers to $X, Y$ in the above state as follows.

  • Add $1024$ to $X$.
  • Add $1024 + 0, 1024 + 1, \cdots, 1024 + (C - 1)$ to $Y$.

It can be verified as follows that this method works.

  • Since the elements of $X, Y$ are at most $1024 + (1000 - 1) = 2023$, the condition that each element is at most $2026$ is satisfied.
  • Since $A, B$ are both less than $1024$, we have $\mathrm{mex}(X) = A, \mathrm{mex}(Y) = B$.
  • Each element of $Z$ whose $2^{10}$ bit is not set is obtained either as the $\mathrm{XOR}$ of an element of $X$ less than $1024$ and an element of $Y$ less than $1024$, or as the $\mathrm{XOR}$ of an element of $X$ at least $1024$ and an element of $Y$ at least $1024$.
    • The former does not include $C$ by the above condition.
    • The latter is $0, 1, 2, \cdots, C - 1$.
  • Since $C$ is less than $1024$, we have $\mathrm{mex}(Z) = C$.

Since the sizes of $X, Y$ are small, you may naively check whether there exist $x \in X, y \in Y$ such that $x \oplus y = C$.

Sample Implementation (C++)