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

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

The official implementations of all the problems are here.

Timeline of the round proposal (may contain spoilers)

1909A - Distinct Buttons

Author: TheScrasse
Preparation: TheScrasse

Hint 1
Solution

1909B - Make Almost Equal With Mod

Author: TheScrasse
Preparation: TheScrasse

Hint 1
Hint 2
Hint 3
Solution

1909C - Heavy Intervals

Author: TheScrasse
Preparation: TheScrasse

Hint 1
Hint 2
Hint 3
Solution

1909D - Split Plus K

Author: TheScrasse
Preparation: TheScrasse

Hint 1
Hint 2
Hint 3
Solution

1909E - Multiple Lamps

Author: TheScrasse
Preparation: TheScrasse

Hint 1
Hint 2
Hint 3
Hint 4
Solution

1909F1 - Small Permutation Problem (Easy Version), 1909F2 - Small Permutation Problem (Hard Version)

Author: TheScrasse
Preparation: TheScrasse

Hint 1
Hint 2
Hint 3
Hint 4
Solution

1909G - Pumping Lemma

Author: TheScrasse
Preparation: TheScrasse

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Solution

1909H - Parallel Swaps Sort

Author: TheScrasse
Full solution: Endagorion, errorgorn
Preparation: TheScrasse, francesco

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Hint 6
Hint 7
Hint 8
Hint 9
Hint 10
Hint 11
Hint 12
Solution

1909I - Short Permutation Problem

Author: TheScrasse
Full solution: errorgorn
Preparation: TheScrasse

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Hint 6
Solution
Разбор задач Pinely Round 3 (Div. 1 + Div. 2)
  • Проголосовать: нравится
  • +354
  • Проголосовать: не нравится

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

Thanks for the fast editorial!

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

del

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

Thanks for the quick editorial. I will probably become expert in this round. Thanks.

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

Can someone explain why this solution receives TLE? I assumed that the time complexity would simply be O(nlogn): 238557809

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

I Feel so stupid for not getting B in an hour

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

MathForce. All problems have math tags.

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

Great round. Thanks for fast editorial

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

238549718 why does my soln of B work?

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

I have a different solution for H so I'll leave it here.

Let's assume $$$N$$$ is even. Consider $$$N$$$ operations $$$(1,N),(2,N-1),(1,N),\cdots,(2,N-1)$$$. These operations reverse the whole permutation. For odd $$$N$$$, one can do similar operations.

During this reversing process, every pair of numbers become adjacent at some moment. Therefore we can "insert" adjacent-swap operations to achieve the arbitrary-swap operation in the final array.

The pitfall is that when we try to do multiple arbitrary swaps, they can interfere with each other during the reversing process. However, if the target permutation has a matching structure, there are no worries about interference.

Then, remember that we can obtain any permutation by composing two appropriate matching permutations. Therefore by repeating the reverse-and-swap process twice one can sort the input permutation.

The time complexity is $$$O(N)$$$ and it's better than the intended solution. However, the number of moves is $$$3N+const$$$ and it's worse than $$$2N$$$. I'm so glad that the author didn't ask me to optimize this constant. (By the way, I'm wondering if it's possible to achieve a better constant factor with my approach.)

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

I solved B ..By getting gcd of all v[x]-v[x-1] and multiply it by 2

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

In problem D, when we are doing operations on a[i]and want to make it to "tar". You are just doing partitioning. Won't there be cases where we partition a[i] into y, a[i]+k-y, and then recursively do operations on both of them?

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

The amount of effort that went into this round is insane, the timeline doesn't really do it justice. Kudos to TheScrasse for never settling on anything less than perfect, and errorgorn for coordinating this extremely demanding set. This turned out to be one of the most quality rounds in my recent memory!

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

Thank you very much for fast Tutorial! I dream of seeing an analysis of the problem D. Thank you for this good round!

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

How to solve F1 with combinatorics?

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

    A way to think of this is to maintain the invariant that the difference of p between consecutive elements in front of the ith element is correct and also to satisfy the current consecutive difference. Denote unallocated elements smaller than i as k.

    If we want to make a consecutive difference of 2, we must assign the current largest element in previous k-1 vacant place, and place any of other k-1 element in current place which is (k-1)*(k-1) ways. Note that placing the current largest element in front of ith element will not break the difference invariant.

    If we want to make a consecutive difference of 1, we can either put the current largest in the previous k-1 vacancy or place any of current k element in current place. This results in 2k-1 ways. As mentioned before, placing the current largest element in front of ith element will not break the invariant.

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

can someone please explain first three lines of solution of problem D ?

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

    let's forget array and assume that we have to deal with single element.

    if this element is greater than k say (k+x),now in one operation we have to find 2 number a,b such that a+b=(k)+(k+x), to reduce complexity of question we are doing this trick

    a+b=(k)+(k+x)=> (a-k)+(b-k)=(0)+(x)

    we don't care about final number we care about how many operation so we reduce all number by k so our operation changed in select number and break it such in two number such that sum is our x((k+x)-(k)).

    in short after reducing by k we don't have to deal with k;)

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

All the problems were great and overall the contest was very enjoyable to solve. Thank you for such a good round!

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

Worst contest for me so far. Didnt solve any. For who wants to see pure pain:

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

Story timeline of the round was something new and quite interesting, I enjoyed it.

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

In question C I have a test case : 5 1 2 3 6 7 3 4 5 7 8 1 2 3 4 5 in which many got answer 14 and 18. according to me answer is 18 as 14 is not possible please comment on it.

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

I was trying to find some cheaters of contest and found this...

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

In the editorial of problem D(solution section),

Shouldn't it be "replace y with x+y" instead of "replace x with y+z"

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

B in O(n): $$$\large 2^{ctz((a_1 \land \cdots \land a_n)\oplus(a_1 \lor \cdots \lor a_n))}$$$

238596786

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

Can anyone explain the concept behind problem D.I didnt understand the editorial

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

    +1

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

    Assume we create a new board $$$B$$$, on which for each number $$$x$$$ written on our original board (call it $$$A$$$), we write the number $$$x - k$$$ on $$$B$$$. Then, let's try seeing what our operation does. So, since $$$y + z = x + k \implies (y - k) + (z - k) = (x - k)$$$ (for the original board), and since we've written $$$y - k, z - k$$$ on our modified board instead of $$$x - k$$$, this gives the observation that on $$$B$$$, our operation just corresponds to replacing $$$x^{*}$$$ by two numbers $$$y^{*}, z^{*}$$$ such that $$$x^{*} = y^{*} + z^{*}$$$. Then, solving this reduced problem is pretty easy (for implementation purposes, just subtract $$$k$$$ from each element of $$$a$$$, and do the calculations on that itself).

»
2 года назад, скрыть # |
 
Проголосовать: нравится -24 Проголосовать: не нравится

spoilers make the whole text unreadable

»
2 года назад, скрыть # |
 
Проголосовать: нравится -34 Проголосовать: не нравится

writing complexity at the end of an editorial is cringe

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

problem B was really something...

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

    it was easy

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

      can u explain editorial?

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

        well it is kind of obvious intuition you get once u see 2 distinct values modulo some k you think of 2 since only two values are possible however then you remmeber all values might be pair hence there is only one value and then this amazing idea gets to u about the next power of 2 which is 4 well since the numbers were allwith the same parity they have only 2 values possible (pair numbers possible values are 2 or 4 and impairs values are 1 and 3) and then again there is possiblity that they all have same value time to check 8 again only 2 values are possible, you can conlcude that the sol requires checking all powers of 2,genius,see this much easier than what the editorial makes it look like.By the way i just guided you trough how the logical thinking went in my brain

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

TheScrasse How does the grader for H work?

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

    Link to comment

    • »
      »
      »
      2 года назад, скрыть # ^ |
      Rev. 6  
      Проголосовать: нравится +13 Проголосовать: не нравится

      (Nvm, this is wrong if you run it on a decreasing array.)

      By the way, isn't the number of moves for the editorial solution actually bounded above by $$$3n/2$$$? Since the number of moves during the second phase is at most the number of Bs after the first phase, which is at most $$$n/2$$$ due to there being no two consecutive Bs and the last letter being an A.

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

      Also curious about these:

      • Were you aware of a solution to H that made $$$3n$$$ operations before the contest? Or did the limits just happen to be large enough to allow that to pass?

      • What was the original solution to H with $$$O(n\log n)$$$ operations?

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

        H with $$$O(n \log n)$$$ operations sounds like a considerably more boring problem, as I believe you can simply simulate merge sort: suppose the right part starts at $$$x$$$, then you can use operations on $$$[x-1,x]$$$, $$$[x-2, x+1]$$$ etc to create a train of moving elements from right to left, and you remove elements from the train when they reach their final positions.

        Other than the very annoying implementation, H with $$$O(n)$$$ operations is a work of art :)

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

          Hm, I don't fully understand.

          By merge sort, do you mean that given two sorted arrays on consecutive ranges, you can merge them into one sorted array?

          If you do operations on $$$[x-1,x], [x-2,x+1], [x-3,x+2], \dots$$$ then this will move some elements right to left over $$$x$$$ and others left to right over $$$x$$$. But how are you removing elements when they reach their final positions? What if there's some element in the middle of the train that you don't want to keep moving?

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

            Here's how I did it: imagine inserting just the rightmost element $$$a_i$$$ of the left half with $$$[x - 1, x]$$$ operations. $$$a_{i - 1}$$$ can trail behind two positions away for free simply by extending the segments to the left (skipping the first one). We stop the trail early if $$$a_{i - 1}$$$ doesn't need to go that far, and proceed to $$$a_{i - 2}$$$. Final case is if $$$a_{i - 1}$$$ needs land next to $$$a_i$$$, in which case we add one more swap at the end to achieve that.

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

              I agree about $$$a_i$$$ and $$$a_{i-1}$$$, but what if $$$a_{i-2}$$$ and $$$a_i$$$ need to keep moving to the right but you don't want $$$a_{i-1}$$$ to keep moving to the right?

              It's true that $$$a_i$$$ must move at least as far right as $$$a_{i-1}$$$, but once you take into account the fact that $$$a_{i-1}$$$ must trail two spaces behind $$$a_i$$$ to move them rightward at the same speed, this is no longer true.

      • »
        »
        »
        »
        2 года назад, скрыть # ^ |
        Rev. 2  
        Проголосовать: нравится +10 Проголосовать: не нравится
        • I was not aware of any linear solution other than the official one. I didn't put $$$2n$$$ as the operation limit to avoid spoilers.
        • The original solution was "put the $$$n/2$$$ smallest elements in the left half of the array in $$$O(n)$$$ operations, then recurse". Some testers found the "merge sort" solution explained by ffao.
»
2 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

hints are very helpful,thanks for editorial

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

Can somebody please explain why my solution of problem C — Heavy Intervals does not work

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

too much math and number theory

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

Very well written editorial! Excellent hints that actually do help a lot if we don't want to see the full solution. Thank you TheScrasse for the good contest and the great editorial.

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

problem D is very nice!

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

The subtasks of F is helpful for some but also misleading many participants including me :(

anyways, good problems and good contest

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

In E, I only understand this phrase in the statement after reading editorial:

If you press the button ui, you also have to press the button vi,(at any moment, not necessarily after pressing the button ui)

It's my fault to not read it properly, and couldn't think that it is possible to press all buttons

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

B was such a good question. Was stuck on the gcd approach for a while before realizing the pattern in the bits.

»
2 года назад, скрыть # |
 
Проголосовать: нравится -10 Проголосовать: не нравится

Lot of mathematics, I feel they should also try not giving just mathematics. B was too hard for me,i never would have thought it that way.

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

Alternative solution for E:

Let's call a subset $$$S$$$ of pressed buttons good if at the end at most $$$\left \lfloor \frac{n}{5} \right \rfloor$$$ lamps turned on. For $$$n \leq 19$$$, the amount of such subsets is $$$\leq 1159$$$. We can find them for each $$$n \in [1, 19]$$$ in $$$O\left(\sum\limits_{n=1}^{19} 2^{n} \cdot n \log n\right)$$$, and then check only them for each $$$n \leq 19$$$ testcase in $$$O(nm + 1159n)$$$.

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

    Actually, you can prove that the number of such subset for $$$n = 19$$$ is exactly $$$\binom{19}{3} + \binom{19}{2} + \binom{19}{1} = 1159$$$ since we can think of each switch $$$i$$$ associated with a vector $$$v_i \in \mathbb{Z}_2^{19}$$$ and all the vectors are independent, so $$$v_1$$$, $$$\dots$$$, $$$v_{19}$$$ is the basis, and we only care when $$$\oplus_{j = 1}^k v_{i_j}$$$ has less than or equal to $$$3$$$ bits on (excluding the case it is equal to zero), so we get the above result.

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

In problem D could we have solved for the smallest x in x*k+ Sum of Ai which is divisible by x+n

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

    Consider the case $$$A = [1, 2, 3].$$$ In this case $$$x = 0$$$ is the best choice, which is incorrect.

    For only positive $$$x$$$ values, consider $$$A = [10, 10, 20]$$$ and $$$k = 10$$$. In this case smallest $$$x$$$ is $$$2$$$ that satisfies the condition, but you can't really make all numbers equal.

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

Can anyone help me with a simple test case for which my submission is wrong for C? It's the same logic as the above solution

https://mirror.codeforces.com/contest/1909/submission/238575783

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

In problem C, making small intervals is not the same as sorting the sequences of left and right endpoints and pairing the corresponding indices. Let, $$$u = L_1,L_2,...,L_n$$$ si obtained after sorting $$$l_1,l_2,...,l_n$$$ and $$$v = R_1,R_2,...,R_n$$$ is obtained after sorting $$$r_1,r_2,...,r_n$$$. Then the new intervals will be $$$[L_1,R_1], [L_2,R_2],...,[L_n,R_n]$$$.

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

Hello, would be great if someone explained why the following idea for B does not work

https://mirror.codeforces.com/contest/1909/submission/238648704

I was thinking of the following test cases

It should seem to always be possible for k to be a single digit value unless all numbers are multiples of 10.

If there are 2 distinct numbers for each last digit, k=10 is always a solution.

If there are more than 2 distinct numbers for each last digit, we can iterate k=2-9 to find a value for which it works

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

In problem E, What the following line does inside the check(int s) function of Jiangly's code 238527503

if (s >> u[i] & ~s >> v[i] & 1)

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

Thanks for interesting tasks.

Little comments for authors. problems $$$B, D, F$$$ are really cool, because they can be solved without any algorithms with only a brilliant idea.

Problem $$$C$$$. Maybe it was better to make more samples, because there were a lot of WA's and a lot of greedy solutions can pass example tests(but of course incorrect).

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

Problem E is kind of funny.I tried to use complicated graph algorithms but failed.And the official solution is cool!I love it!

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

I have another solution for problem G. It is easier than the intended one in my opinion, at least idea-wise.

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

In D, "Now, the operation becomes "replace x with y+z such that x+y=z+k⟹(x′+k)+(y′+k)=(z′+k)+k⟹x′+y′=z′ ". Therefore, in the shifted problem, k′=0" .

I think it should be y+z = x+k instead of x+y = z+k.

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

I can understand the solution of G now,but I've got no idea about how the vital observation "$$$(a,b)$$$ is valid then $$$(a+1,b+1)$$$ is valid if and only if $$$s_{b+1}=t_{b+1}$$$" was found.What inspired you think about that?Can someone help me?

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

    Actually, I only found it while preparing the problem (with constraints $$$n, m \leq 2 \cdot 10^5$$$). I was trying to build strong tests (where the valid $$$y$$$ of fixed length are not consecutive), but I ended up proving it's not possible.

    I'm curious about how actual contestants figured it out.

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

Can someone explain the intution behind problem C?

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

in problem c I'm trying to follow the editorial in the proof section he is saying at the third line If you swap ri and rj, the cost does not increase. I did that on the example n=2 provided and the cost increased from 6 to 7 first step he said match them any other order so: [2,4] [1,3] then he said You have also assigned some cost ci to [li,ri] and cj to [lj,rj] . [2,4] ci=2 [1,3] ci=1 now cost is 6 then ** If you swap ri and rj, the cost does not increase. ** swapping here will make the cost 7 so I don't get it can you please explain what is wrong here

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

Can someone help me to explain the complexity of problem E plz?

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

For D, the shifting part is still unclear to me(ik what is being done ,but how is it correct and how to think of it) thnx in advance if someone can spare their time or share related resources

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

    I was really struggling for a while to come to grips with this solution and I think I am now (mostly) convinced of why it works, so I'll try to explain my way of thinking about it.

    Imagine a number line with numbers x, y and z marked such that y + z = x + k.

    Now think about the operation you can do: y + z = x + k. Going back to the number line, what this operation means is you would have to pick x and move it k unities to the right, then pick two numbers x and y such that their sum "lands" in (x + k) and not x.

    For each of those three numbers now, mark in the number line its value shifted k unities to the left, and call these new guys x', y' and z'. Clearly you can represent x by (x' + k), y by (y' + k) and z by (z' + k). So, looking again at our operation, we have (y' + k) + (z' + k) = (x' + k) + k -> y' + z' = x'.

    What that tells us is that if we had a magical way of taking every number on our line and shifting it k unities to the left, when we would execute the operation on an original number x, instead of doing that complicated process (moving it k unities to the right and only then finding numbers which add to it), we could map x to its representation in the shifted "world" and find two other numbers, also in the shifted world, such that their sum is equal to the representation of x.

    Our magical way of doing this shift is simply to take every number given in the input and subtract it by k. Now, for every operation we do in those numbers (including gcd), we are working with numbers from our shifted world; so we can now solve the problem as if k didn't even exist. Hope this is helpful in some way :)

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

can someone give the intuition behind the idea of "shifted problem" for D ? is it a trick or just random manipulation for this specific problem

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

In D you can also do the reverse problem: Start at the final state which is a bunch of identical elements then apply "combine and subtract $$$k$$$" operations and arrive at a similar solution with algebra.

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

problem D is amazing i have different approach for. suppose mn and mx are the max and min elements if mx == mn ans is 0. if mn <= k && k <= mx we can neve the values of array to a single value. if k < mn || k > mx ans will exist. assume at the end all the elements are equal to x so the last element we remove = 2 * x — k. second last element we would remove will be either 2 * x — k or 3 * x — k and so on. it shows that all the elements in the initial array is of the form .. pi * x — (pi — 1) * k, after rearranging pi(x — k) + k. now ans would be just summation of all pi.

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

Problem I is 1900!!!

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Nice contest

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Fast and on point editorial.

»
19 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

in B , Learnt that while shifting for large powers to use 1LL<<i, else shifting wont work for large powers & (1<<i) while shifting make sure it doesnt fudge with the brackets

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

Problem F is such a masterpiece!

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

For a newbie like me, who are struggling to understand problem B

The Last Digits Picture Write every number in binary. Now look at only the last j digits of each number. j=1: last 1 bit → possible values: 0, 1 j=2: last 2 bits → possible values: 00, 01, 10, 11 j=3: last 3 bits → possible values: 000, 001, 010, ... Key observation: if all numbers share the same last j bits, say they all end in 1 — then at j+1, each number can only end in 01 or 11. Still at most 2 distinct endings! So once you're at 1 distinct group, the next step gives you 1 or 2 — never 3+. Keep increasing j until you first see 2 distinct endings. Done. Example: a = [1005, 2005, 7005, 11005, 16005]

j=1 → 1, 1, 1, 1, 1 → 1 distinct ✗ j=2 → 01, 01, 01, 01, 01 → 1 distinct ✗ j=3 → 101, 101, 101, 101, 101 → 1 distinct ✗ j=4 → 1101, 1101, 1101, 1101, 0101 → 2 distinct ✓ answer = 2⁴ = 16 Complexity: O(n log maxA)