Блог пользователя do_good_

Автор do_good_, история, 7 лет назад, По-английски

hello, how to solve problem f of today's abc 126 ? https://atcoder.jp/contests/abc126/tasks/abc126_f . since editorial is in japanese.

i also request rng_58 to add english version of editorial , since the rating has been increased to 1999.

  • Проголосовать: нравится
  • +8
  • Проголосовать: не нравится

»
7 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится +14 Проголосовать: не нравится

First, hardcode the M = 1 case. For all other M, there exists an answer if and only if K < 2^M. In these cases, we can proceed as follows:

  1. Print all numbers 1 through 2^M-1 except K.
  2. Print K.
  3. Print the same numbers in step one, but in the reverse order.
  4. Print K again.

For the non-K numbers, this works because in the interval between them, various numbers appear twice (and thus don't contribute to the xor result) and K appears once, leading to an xor of K. For K, the xor includes all the numbers in step three, meaning every number from 1 to 2^M-1 except K. Note that this is equal to the xor of all the numbers from 1 to 2^M-1 (including K) and K. We can prove that the xor of the numbers 1 to 2^M-1 is zero, so our xor is xor(0, K) = K, as desired.

The claim that xor(1, 2, ..., 2^M-1) = 0 is only true for M >= 2. This is why we must hardcode the M=1 case (the answer is 0 0 1 1 or its reverse if K=0 and -1 otherwise). M=0 works with this algorithm anyway, as with K > 0, we correctly print -1, and with K = 0, we correctly print 0 0.

»
7 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится +1 Проголосовать: не нравится

I have a solution, but I am not sure if it is correct because when I submitted it in the contest I forgot to leave spaces between numbers in the output, and now the verdict is too slow, so I am still waiting.

So my solution (without being sure that its correct) is this:

if K = 0, then sequence has that form: $$$0 \; 0 \; 1 \; 1 \; 2 \; 2 \; 3 \; 3 \cdots (2^M - 1) \; (2^M - 1)$$$

if K is larger than $$$2^M - 1$$$, then we can't create a xor equal to K with numbers that are in the range $$$[0, 2^M - 1]$$$. So we return -1.

In any other case (when $$$0 \leq K \leq 2^M - 1$$$), we follow this strategy. Initialize an array and add K. Now for every $$$0 \leq i \leq 2^M - 1$$$ different than K, insert i in the front and back of the current array. Finally add the second K in the end of the array.

For example for M = 2, K = 2, array/sequence is 3 1 0 2 0 1 3 2.

For every number different than K, the condition is satisfied because every term is deleted with its pair except the middle K. Now for the pair of K's, the condition is satisfied as well. This is because $$$0 \; \text{xor} \; 1 \; \text{xor} \; 2 \; \text{xor} \; \cdots \; \text{xor} \; 2^M - 1 = 0$$$, so if you remove one number, the xor of the rest equal to that number.

»
7 лет назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

Btw, the contest was rated ? Because I don't see any updates there.

»
7 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

The main idea that needs to be used in $$$F$$$ is that $$$x \oplus x = 0$$$, for any $$$x$$$.

It is not possible for us to reach any $$$x$$$, if $$$x \gt 2^M$$$ as every integer only has $$$M$$$ bits.

Let us leverage this. Suppose we want to reach $$$K$$$. If we print $$$K$$$ and then print the remaining numbers on one side and the same numbers on the other side in reversed order, then we will always have xor $$$= K$$$ for any pair of numbers.

The only exception is what will be the xor between $$$k$$$ and $$$k$$$ ?

To Solve this, we will simply put $$$K$$$ at one end !

Now, $$$K \oplus 1 \oplus \dots \oplus K$$$ will simply be $$$K \oplus (1 \oplus 2 \oplus \dots \oplus 2^M)$$$.

The Xor of all numbers from $$$1$$$ to $$$n$$$ is $$$0$$$ whenever $$$n$$$ is a multiple of $$$4$$$. All powers of 2 greater than $$$2$$$ are powers of $$$4$$$.

So the expression simply becomes $$$K \oplus 0 = K $$$

Here is my explanation. My solutions to the other problems are included as well.