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

Автор ScarletS, история, 3 года назад, По-английски

A — Very Very Primitive Game

Solution

B — Magic 3

Solution

C — Bowls and Dishes

Solution

D — Staircase Sequences

Solution

E — Magical Ornament

Solution

F — Shift and Inversions

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

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

In F, the change should be n — 1 — 2*a[i].

»
3 года назад, # |
  Проголосовать: нравится -9 Проголосовать: не нравится

problem F was very interesting

»
3 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

For problem D, I iterated over the length of the series from 1 to 2000000. Then I binary searched the start element for the cur length and if we found the sum exactly equal to n, then add 2 to the answer.

My submission

  • »
    »
    3 года назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    Can you explain how you figured the range will be till 2000000?

    I tried till 1000000 and didn't work.

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      The longest length series you can make in worst case out of natural numbers should start from 1.

      Lets say that length is $$$l$$$. Then $$$\sum_{i=1}^n l = \frac{l(l+1)}{2} = n$$$

      Here n is the sum we want.

      So $$$l \leq \sqrt{2 * n}$$$

      Hence $$$l$$$ will be less than 2000000

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Can someone give a solution for C without using bitmasking?

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится +4 Проголосовать: не нравится

    You can use recursion to find all the ways to pick either $$$C_i$$$ or $$$D_i$$$, but it ends up doing the exact same thing as bitmasks, only slower and messier.

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Ya I understood.Thank you so much.

    • »
      »
      »
      3 года назад, # ^ |
      Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится
      Code
»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

can anyone tell me how to find these time complexities...I can find easy ones like O(n) and O(n^2) but not like -O(K(N+M)+2K∗K2)..how to learn that...I'm struggling with this for a week.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Hi, sorry for the late response. I don't think you need to learn/find these non-standard complexities, rather, you should learn to recognise and break down problem statements and work on approaching unfamiliar problems. In that problem the $$$K(N+M)$$$ and the $$$2^K*N^2$$$ are essentially separate sub-problems, first to calculate distance to all nodes with BFS ($$$O(N+M)$$$), $$$K$$$ times, for each gem. From there, we can reduce it to a classic $$$O(2^K*K^2)$$$ bitmasking problem. I hope this helped! :)

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      hello, I'm a beginner and I want to ask you one more thing "if the jth bit is "on" (i.e. i AND 2j=2j)" what is the meaning of this? I mean if the jth bit is on then how are we deciding that we will give the ball to C[j] or d[j](what it means if the jth bit is on in the context of this problem)...I hope you know what I mean.

      • »
        »
        »
        »
        3 года назад, # ^ |
          Проголосовать: нравится +3 Проголосовать: не нравится

        It's just a technique to iterate over all combinations of $$$0$$$s and $$$1$$$s. While iterating from $$$0$$$ to $$$2^{K-1}$$$, all masks of length $$$K$$$ can be achieved. You may have seen the recursive version before, think of this as another way to do that only faster and less liable to mistakes.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by ScarletS (previous revision, new revision, compare).

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Hello, thanks for the great editorial. I just wanted to ask that why there is a second If in solution of staircase sequence??

  • »
    »
    3 года назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

    We can find all the divisors of $$$N$$$ in $$$O(\sqrt{N})$$$ by only checking up to $$$\sqrt{N}$$$, as every every divisor below the square root has a conjugate divisor above it. The exception to this is $$$\sqrt{N}$$$ itself if $$$N$$$ is a square number, since its conjugate divisor is also $$$\sqrt{N}$$$. We can avoid double counting by ensuring that the second addition to the answer is only done if $$$i^2 \neq N$$$.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Thanks for the editorial! BTW can you explain why the sequences in F will change by moving the first element to the end?

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

User Editorial by kostia244

kinda sus

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

For problem E,if the problem description change to “find the minimum number of distinct stones needed to form such a sequence.”,how to solve it? thx.

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

For problem D, my output was 2 times the number of odd divisors of N. Submission

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by ScarletS (previous revision, new revision, compare).

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Problem F was an owsam one to me