SkyWave2024's blog

By SkyWave2024, history, 5 weeks ago, In English

Code: 293163701

First, notice that

  • a string like $$$\texttt{RDRDRD}$$$ will change the array $$$[a,a+1,\ldots,b]$$$ to $$$[a+1,\ldots,b,a]$$$. Let's call this operation shift.
  • a string like $$$\texttt{RRRDDD}$$$ will change the array $$$[a,a+1,\ldots,b]$$$ to $$$[b,b-1,a,a+1,\ldots,b-2]$$$. Let's call this operation shuffle.

Now let's start sorting the array. Suppose $$$a$$$ is a permutation of $$$1 \sim n$$$. The basic idea is, in the $$$i$$$-th turn move $$$i$$$ to the end.

Let's consider the $$$i$$$-th turn, let $$$i$$$'s current position be $$$pos$$$. Now the array looks like $$$[\ldots,i,\ldots,1,2,3,\ldots,i-1]$$$.

  • In most cases, you can do a shuffle for $$$a[1,pos + 2]$$$. Now we are on $$$(pos+2,pos+2)$$$ and $$$a_{pos+2} = i$$$, then do a shift for $$$a[pos+2,n]$$$ is ok. To do this, we should have $$$pos \le n - i - 1$$$ so that the shuffle won't affect the $$$1,2,\ldots,i-1$$$ part.
  • Otherwise, Let's first do a shuffle for $$$a[1,pos]$$$, and shift for $$$a[pos,n]$$$. Now $$$a_n$$$ is a random number. Then shift the whole array and we have $$$a_n = i$$$. Then shuffle the whole array, now we have $$$a_1 = i$$$ and $$$a_n = i - 1$$$, do another shift for whole array is ok. For example, we want to move $$$4$$$ to the end, we do $$$[6,5,4,1,2,3] \to [4,5,1,2,3,6] \to [5,1,2,3,6,4] \to [4,6,5,1,2,3] \to [6,5,1,2,3,4]$$$.

Please note that the first case costs us $$$1$$$ operation, but the second one costs us $$$4$$$. As a result, we may need more than $$$2n+4$$$ operations to sort finish it. Now, if we use more than $$$2n+4$$$ operations, shift $$$a[1,i]$$$, shuffle $$$a[i,n]$$$ before everything begins. Try each $$$i$$$ until we use less than $$$2n+4$$$ operations, and it get $$$\color{green}{\text{Accepted}}$$$!

I believe it can be hacked, but i don't know how. Can anyone hack it :)

  • Vote: I like it
  • +36
  • Vote: I do not like it

»
5 weeks ago, # |
  Vote: I like it +24 Vote: I do not like it

I don't know what exactly happened in the code, but I hacked it just by stress-testing :)

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    Ok now I add a new shuffle and passes again! 293165779

    I have made 10000 stress tests with $$$n \le 10$$$ now! :)

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    AC again and this time I have made $$$10^7$$$ stress tests :) 293166861

    • »
      »
      »
      5 weeks ago, # ^ |
        Vote: I like it +18 Vote: I do not like it

      It's getting tough. I think I tried around $$$10^8$$$ tests to hack this time.

      • »
        »
        »
        »
        5 weeks ago, # ^ |
          Vote: I like it +7 Vote: I do not like it

        Now it passed $$$5 \times 10^8$$$ stress tests :) maybe it will be not easy to hack it by directly stress tests :) 293168216