MathModel's blog

By MathModel, history, 10 months ago, In English

Thank you for participating !

Special Thanks to hxu10 for giving me the chance to write the editorial and for maomao90 for enhancing the editorial !.

Editorial of Problems E and F are written by hxu10, and the rest are written by me. I hope they're insightful and concise, please let me hear your opinion about it or any feedback in general 💙.

2156A - Pizza Time

Hints
Solution
Implementation 1 (MathModel)
Solution 2
Implementation 2 (MathModel)
Rate The Problem !

2156B - Strange Machine

Hints
Solution 1 : O(nq log A)
Implementation 1 (MathModel)
Bonus Hints
Solution 2 (Bonus) : O(n+qlog^2 A)
Implementation 2 (MathModel)
Rate The Problem !

2156C - Maximum GCD on Whiteboard

Hints
Solution
Implementation (MathModel)
Rate The Problem !

2156D - Find the Last Number

Hints
Solution
Implementation (hxu10)
Rate The Problem !

2156E - Best Time to Buy and Sell Stock

Hints
Solution
Implementation (hxu,PyPy)
Implementation (maomao90,C++)
Rate The Problem !

2156F1 - Strange Operation (Easy Version)

hxu10's Solution
Tester's Solution
MathModel's Solution (Bonus/Challenge)
Rate The Problem !

2156F2 - Strange Operation (Hard Version)

Hints
Solution
Implementation (hxu10,PyPy)
Rate The Problem !
  • Vote: I like it
  • +159
  • Vote: I do not like it

»
10 months ago, hide # |
 
Vote: I like it +9 Vote: I do not like it

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

»
10 months ago, hide # |
Rev. 2  
Vote: I like it +15 Vote: I do not like it

what is the point of system testing $$$A-D$$$ if the pretests are the same as the sys tests?

also, nice leetcode reference in $$$E$$$

»
10 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

how you guys find that [2*i,3*i,4*i] thing in C during contest? still cant arrive at that.

  • »
    »
    10 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +1 Vote: I do not like it

    for a number greater than equal to 4i ( say q*i + r, where q>=4, 0<=r<i ) split to i,i+r,(q-2)*i and so i+r will be removed ( holding the inequality i <= i+r < (q-2)*i )

    if a number is less than 4*i then you cant split it such that their gcd will be i so the number themselves have to be divisible by i

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Actually up to 3*i is enough, for the numbers >= 4*i you can apply split. How to come up to than, just try to be greedy and find max amount of numbers that you can use split.

    • »
      »
      »
      10 months ago, hide # ^ |
      Rev. 2  
      Vote: I like it 0 Vote: I do not like it

      upto 3i is not enough

      how will you split if it is 3i+1

      =4i is required if we have 4i+1 we can split i,i+1,2i

      • »
        »
        »
        »
        10 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        I meant divisors

      • »
        »
        »
        »
        5 months ago, hide # ^ |
        Rev. 3  
        Vote: I like it 0 Vote: I do not like it

        like let us say , take a number a = 2*i and we wanna make i as the gcd . so 2i is already a good element and then , let us say 2i+1 , how do we split it? i guess we can do it by i , i and 1 which satisfies 1<=i<=i , similarly upto 3i we can make the split like i , i and r where 1<=r<=i-1. and then 3i is also a good element , now how do we split 3i+1 ? i , 2i , 1 , where 1<=i<2i , similarly we'll be keep doing this upto 4i and will split it like , i , 2i and r where 1<=r<=i-1 and we will always remove r. According to this numbers >=2i are always good , but i think in editorial it is not the case... so where am i wrong ? //UPDATE

        i got it i can only remove x2 , but i was removing x1 always , sorry for the rookie doubts..

  • »
    »
    10 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    if g is the gcd you are considering: a number x which is n*g + r can always be split to g, g+r, (n-2)*g, but for g<g+r<(n-2)*g to hold, the number should be at least 4*g so we can split it to g,g+r,2*g otherwise it wont hold

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

i used binary search for A :( and Good B

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
10 months ago, hide # |
Rev. 8  
Vote: I like it +3 Vote: I do not like it

Why Binary search is required for E — Hint 1.2 version ? (easier version where Alex moves first ? ).

Can't we just maintain two values for each index... primaryMin,secondaryMin on prefix,,, and primaryMax,secondaryMax in suffix.

Now, we assume, we are locking current index i as our first index (As alex)... so in next move Hao will try to delete primaryMax on right(suffix), or primaryMin on left(prefix), and we might get answer in O (N). ( loop i from 1 to N ). We will pick the index, which gives highest return.

Anything wrong with this approach ??????

cc : Editorialists ( maomao90 , MathModel ).

  • »
    »
    10 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +8 Vote: I do not like it

    You can do it without binary search (which I did), although it takes a bit more work :

    For each index $$$i$$$, find the 3 best targets $$$j_1, j_2, j_3$$$, which give results $$$a_1 \geqslant a_2 \geqslant a_3$$$. Now if Hao wants to deny the result $$$a_3$$$, he can only do so by removing $$$i$$$ in the first move. If he want to deny $$$a_2$$$, he can do so only by removing either $$$i$$$ or one of $$$j_1, j_2$$$ in the first move. He can always deny $$$a_1$$$.

    So sort all events (value, list of possible cuts) by decreasing value, and find the cut which is contained in the maximum prefix of such events by merging the lists.

    You still end up with $$$O(n log(n))$$$ though since you need the sort.

»
10 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

For A problem the first approach of (n-1)//2 wont it fail for many testcases like say 13 which should give optimal answer to be 5 but this code gives 6...someone pls help me out here.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

FAST EDITORIAL! Thanks for the contest :)

»
10 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

C was one heck of a question.

Spent 1.5hrs on that and still not able to solve.

  • »
    »
    10 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    first, you need to establish a logic that... any number(N) can be represented (splitted into three parts) for base(x), if that N >= 4*x.

    (WHY?).

    Once you have established above logic, its just frequency counting question... keeping suffix sum is sufficient to solve...

»
10 months ago, hide # |
 
Vote: I like it +4 Vote: I do not like it

thanks for quick editorial

i had correct idea of D .. but had n in the formula instead of n-1 by mistake.. so couldn't prove it will be < 2n ... noooo !!!

»
10 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

I really liked the problem C. worth solving!

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Problem C is beautiful. Thanks for the quick editorial!

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Loved the problem C :3

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Very detailed editorial with step-by-step approach to the solutions. This is very helpful for beginners.

»
10 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Fast editorial forces:)

»
10 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Thanks for the super great editorial ! wasn't able to solve B in the contest, but the editorial really helped me understand the approach well ! :)

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Nice editorial :)

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

loved problem B

»
10 months ago, hide # |
Rev. 2  
Vote: I like it +44 Vote: I do not like it

I'll write another greedy for F1, which can be seen as a proof for the Bonus solution :

Consider the smallest $$$i$$$ that can be changed, that is $$$i$$$ appears before $$$i - 1$$$ and $$$i - 2$$$. Then doing the move from $$$i$$$ decreases lexicographically the permutation, but also makes any move from $$$j \gt i$$$ easier (if $$$j \gt i + 2$$$ then nothing changes, for $$$j = i + 2$$$, $$$i$$$ is pushed to the right, and for $$$j = i + 1$$$ the min of $$$i - 1$$$ and $$$i$$$ is pushed to the right).

Hence there is no good reason not to do this move, so do it and start again until there are no moves left. Alternatively, it is equivalent to reducing taking the position of $$$3$$$ and reducing it as far as you can, then the position of $$$4$$$ and reducing it as far as you can, etc...)

You can also adapt this solution with a Treap (on the inverse permutation) to pass F2, see my submission

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it +21 Vote: I do not like it

    I don't understand how this is proof at all. I agree that applying the operation on $$$i$$$ doesn't make any other operation $$$j \gt i$$$ invalid, but how does that imply that performing $$$j$$$ first doesn't result in something lexicographically smaller?

    • »
      »
      »
      10 months ago, hide # ^ |
      Rev. 2  
      Vote: I like it +29 Vote: I do not like it

      I'll give three proofs :

      1 : proof by AC submission

      2 : proof left to the reader

      3 : let's denote by $$$(i, j)$$$ the operation on position $$$i$$$ when $$$p[i] = j$$$, and consider some optimal sequence of operations $$$(i_k, j_k)$$$. If there exists some $$$(i_1, j_1)$$$, $$$(i_2, j_2)$$$ one after the other such that $$$i_2 \ne i_1$$$ and $$$j_2 \leqslant j_1$$$, we can swap the two operations since actually we must have $$$j_2 \ne j_1$$$, $$$j_2 \ne j_1 - 1$$$ since $$$j_1 - 2$$$ was placed before them, so the two operations are disjoint.

      Hence by noting $$$(i, j \rightarrow j')$$$ some sequence $$$(i, j), (i, j - 2), \ldots, (i, j' + 2)$$$, there exists some optimal sequence of operations of the form $$$(i_1, 1 \rightarrow v_1), (i_2, 2 \rightarrow v_2), \ldots, (i_n, n \rightarrow v_n)$$$

      Now for such a sequence, if some $$$(i, j)$$$ is not reduced as much as it could, reducing it further only makes subsequent reducing easier (this is in essence my discussion above, since every subsequent value must be to the left of all values it skips on the way down), hence reducing each value as much as you can is optimal (any reduction at position $$$i' \lt i$$$ will still happen, so the prefix stays the same and the value at position $$$i$$$ decreases).

      • »
        »
        »
        »
        10 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        Is this proof correct? Lemma 1:- A operation decreases number of inversions in the permutation by 2

        Lemma 2: Applying operation on increasing order of values will never kill a operation that I could have done before of doing this while the inverse is not true.

        Now, As each operation decreases my no. of inversion by 2. if we could maximize the number of operation that we could do we are bound to achieve the lower bound in number of inversions which will give the lexicographically minimal.

        • »
          »
          »
          »
          »
          10 months ago, hide # ^ |
          Rev. 2  
          Vote: I like it +1 Vote: I do not like it

          Minimizing the number of inversions doesn't necessarily yield the lexicographically minimal permutation, $$$[1, 5, 4, 3, 2]$$$ has more inversions than $$$[2, 1, 3, 4, 5]$$$ while being smaller.

          And since swapping two operations actually changes the resulting permutation, you still need to show that it is optimal to do them in increasing order, which is what I clarified above .(Also you have to allow applying $$$i$$$, then $$$i - 2$$$, then $$$i - 4$$$, etc in order from the same position, so it cannot be all increasing)

      • »
        »
        »
        »
        10 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        Wow, the first part is quite nice, thanks for the proof!

      • »
        »
        »
        »
        10 months ago, hide # ^ |
        Rev. 2  
        Vote: I like it 0 Vote: I do not like it

        great proof, i think the only flow in your earlier proof was not considering making an operation on a larger value that could later help smaller values but the second paragraph in the second proof clears everything.

        But my question to you is how do you sort this sequence (i1, 10), (i2, 11), (i2, 9), (i2, 7), (i2, 5), (i1, 8)

        "there existing an optimal sequence of moves in the form of blocks" is indeed true as its a weaker form of the constructive solution, but i dont think what you provided is enough to say that any optimal solution can be sorted down to a sequence of blocks

        • »
          »
          »
          »
          »
          10 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          The assumption in the sequence you gave is that $$$8$$$ is in position $$$i_1$$$, then the operation $$$(i_2, 9)$$$ puts $$$7$$$ in $$$i_1$$$ where $$$8$$$ was, so the operation $$$(i_1, 8)$$$ doesn't exist.

          I agree that my proof was evasive, but if you think about swapping an operation with a whole block, you can use the same casework to see that for both operations to be valid, they have to be disjoint and the swap is valid

»
10 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Can anyone give me some methods how to approach the problem C?

  • »
    »
    10 months ago, hide # ^ |
    Rev. 4  
    Vote: I like it +8 Vote: I do not like it

    Suppose we want a number 'X' to be the answer then either all the numbers should be divisible by 'X' or we are able to break down these numbers into multiples of X, then only it can be our answer.

    First observation is that firstly remove all the numbers < X, as if any of them are present then "X" can't be the answer. Hence, if you have 'Y' numbers < 'X', then apply 'K' operations to remove them . If 'K' < 'Y', then no matter what you do you can't remove all numbers < X, so it can never be the answer.

    Second observation is that, after trying out few examples you will see that if you want to break a number 'Y' into multiple 'X' then it should be at least 4*X.

    PROOF :

    For a number 'Y' which is not divisible by 'X', then for it to be converted into a multiple of 'X' you want it to break such that the non-multiple multiple part of 'Y' is in the middle. Hence, one possible greedy construction :
    First part = 'X' (smallest)
    Second part = 'X' + non-divisible part (second largest)
    Third part = multiple of 'X' >= second part (largest part)

    Looking at this gives us that the third part would be bare minimum 2*X, as second part is always greater than 'X' so, the nearest multiple divisible by 'X' and greater than 2nd part, would be 2*X.

    SO, summing these up gives : X + (X + non-divisible part) + 2*X, which is gives us a lower bound of 4*X.

    Hence, we don't care about any number >= 4*X, as, we can always make them divisible by 'X'. So, we are left with numbers smaller < 4*X, as we can't change them, only option left with us is to delete non-divisible ones. Hence, we check that if remaining numbers other than the ones >= 4*X, and also, multiples of 'X' less than 4*X, i.e. freq[X] + freq[2*X] + freq[3*X], are <= 'K' or not. If YES then this 'X' can be our answer else it can't be.

    Here's my code. Hope this helps!

    • »
      »
      »
      10 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      bro why it should not be 3X , why it would be 4X always

      • »
        »
        »
        »
        10 months ago, hide # ^ |
        Rev. 2  
        Vote: I like it 0 Vote: I do not like it

        Suppose we have a number Y such that 3*X < Y < 4*X i.e. $$$Y \bmod X \ne 0$$$.

        Now, if we try to partition it into three parts such that $$$Y = Y_1 + Y_2 + Y_3$$$ and $$$Y_1 \le Y_2 \le Y_3$$$, then we must make sure that both $$$Y_1$$$ and $$$Y_3$$$ are multiples of $$$X$$$, which obviously leaves the middle part $$$Y_2$$$ with the non-divisible remainder (since $$$Y$$$ itself isn’t divisible by $$$X$$$).

        REMEMBER : We want multiples of $$$X$$$ at both the end, hence $$$Y_1$$$ and $$$Y_3$$$ must be multiples of $$$X$$$

        So, we first assign the lowest possible multiple of $$$X$$$ at the start: $$$Y_1 = X$$$. This leaves us with the remaining part : $$$Y - X \in (2X, 3X)$$$.

        Now, let the remainder $$$R = Y \bmod X$$$. We’ll have the non-divisible part (the remainder) somewhere inside (in the middle). But leaving it alone would make it smaller than $$$Y_1$$$, since any remainder is always less than the divisor ($$$R \lt X$$$). Hence, $$$Y_2 = R$$$ would violate the condition $$$Y_2 \ge Y_1$$$. So, we must increase $$$Y_2$$$ without affecting the multiplicity of $$$Y_1$$$ and $$$Y_3$$$. The only simple way to do that is to add another $$$X$$$ to it i.e. $$$Y_2 = X + R$$$.

        Now, the last part becomes:

        $$$Y_3 = Y - Y_1 - Y_2$$$
        $$$Y_3 = Y - X - (X + R)$$$
        $$$Y_3 = Y - 2X - R$$$

        Since, we assumed $$$Y \in (3X, 4X)$$$, this means now, $$$Y_3 \lt 4X - 2X - R \lt 2X - R$$$.
        But $$$Y_2 = X + R$$$, and because $$$R \gt 0$$$, we get $$$Y_2 \gt X$$$. But having $$$Y_3 \lt Y_2$$$ is a violation, breaking the original order of $$$Y_1 \le Y_2 \le Y_3$$$.

        Hence, for any $$$Y \lt 4X$$$, such a valid partition is IMPOSSIBLE!.

        Now, if $$$Y \ge 4X$$$, we can take :
        $$$Y_1 = X$$$, $$$Y_2 = X + R$$$, and $$$Y_3 = Y - 2X - R$$$.
        Here $$$Y_3 \ge 2X$$$, so the ordering holds ($$$Y_1 \le Y_2 \le Y_3$$$), and both $$$Y_1$$$ and $$$Y_3$$$ are multiples of $$$X$$$.

        Hence, the minimum threshold for proper division of $$$Y$$$ into $$$Y_1, Y_2$$$, and $$$Y_3$$$ is Y >= 4*X.
        You may try out few examples yourself to see it more clearly!
        Hope this helped :)

    • »
      »
      »
      10 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      great explanation actually

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I managed to squeeze some lame recursive brute-force in F1 lol 345611854

»
10 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Hey in F1, Can you please clarify me! Is reducing the odd first before the even is not same as reducing the minimum (which is satisfying the conditions)? My submission 345616139

»
10 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

It was a great contest.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Till this date, I was wrong about the sum of (n + n / 2 + n / 4 + n / 8 + ... ), which is actually 2n. I thought this series is same as (n + n / 2 + n / 3 + n / 4 + ...) which is nlog(n). So I missed the simple solution of problem D.

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    You're mixing between :

    $$$\displaystyle \sum_{i=0}^{\infty} \frac{n}{2^i}$$$

    and

    $$$\displaystyle \sum_{i=0}^{\infty} \left \lfloor \frac{n}{2^i} \right \rfloor $$$

    The first can be obtained with G.P sums to end up with $$$2n$$$

    the second is obviously less , since either of the following cases will happen :

    • $$$n$$$ is a power of two , hence the sum will be $$$n+\frac{n}{2}+\frac{n}{4}+...+1=2n-1$$$

    • there exists a power of two $$$j$$$ such that $$$n \bmod 2^j \neq 0$$$ so the sum will be off by at least two (i.e. $$$ \lt 2n-1$$$).

    Thus in all cases the sum will be $$$ \lt 2n$$$.

    • »
      »
      »
      9 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      but in the case where its ceil(n/2^i), the sum can be larger than 2*n. Thus the editorial for D is incorrect. When you plug in the value 34 for the formula in hint 3, you get 69 which is not <= 2*34. So for some values of n, the editorial solution exceeds the query limit.

      • »
        »
        »
        »
        9 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        uh , It's floor not ceil though and floor $$$\le$$$ ceil , obviously in our case it's $$$ \lt $$$

        $$$\displaystyle \sum_{i=0}^{\infty} \left \lfloor \frac{n}{2^i} \right \rfloor$$$

        if we took your example ,

        $$$\left \lfloor \frac{34}{1} \right \rfloor+\left \lfloor \frac{34}{2} \right \rfloor + \left \lfloor \frac{34}{4} \right \rfloor+\left \lfloor \frac{34}{8} \right \rfloor+\left \lfloor \frac{34}{16} \right \rfloor+\left \lfloor \frac{34}{32} \right \rfloor$$$

        so we've

        $$$34+17+8+4+2+1=66 \lt 2 \times 34=68$$$

        so it still holds.

        • »
          »
          »
          »
          »
          9 months ago, hide # ^ |
           
          Vote: I like it 0 Vote: I do not like it

          Maybe we're talking about different problems? Im talking about 2156D — Find the Last Number Hint 3 clearly displays a sum of ceilings. Plug in n = 34 into hint 3 for 2156D and its clear the hint (and thus the solution) are incorrect. Maybe im missing something?

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Just a small typo in Bonus solution of Problem B, if si = 'B' perform ai = ai/2^min(x,y) there instead of Logn it should be Log(ai).

»
10 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

I upsolved F1 and I found it easier than D. I wish I had seen it in contest. Wasted my time in D.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone help me spot out edge case for my code, it fails at test-5

Code
What I did
»
10 months ago, hide # |
 
Vote: I like it +26 Vote: I do not like it

It is possible to solve E in O(n).

We also need to make an observation that the maximum value will be achieved on the 4-th move.

Just like in the editorial let's first consider a game where Alex goes first. Now the game is reduced to one move by Alex, one block by Hao, and final move by Alex. Let's compute the value for each index i that Alex will take on the first move. To do that we need to know 2 smallest values for all j < i and 2 largest values for j > i. This can be easily done in O(n), we will also need to store the indices of largest and smallest values.

Now for each i we compute an array of possible second moves. This will be up to 4 possible moves. We know that Hao will remove the largest element from the list, so the answer is the second largest.

Now we know what will be the answer if Alex started. But we know that Hao is starting and it is optimal for him to disturb Alex'es best move. This can happen if Hao removes best starting move for Alex, or one of 4 possible values that Alex would take on 2nd move.

So we solve the problem again with 5 possible elements removed. Each Alex starting solution takes O(n) time and will be done at most 6 times. 345606017

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For E, Can anyone please tell me how the following case is covered in the author's implementation where exactly one index has adj[i].size() > 2. for that i, Let say it has 5 children, with 2 children having degree = 2 and 3 children having degree = 1. But we only added the edge for 3 children which can be all of those which had degree = 1, in that case when we remove the index "i", according to the code we were not able to cover all 2 degrees but in reality we did removed all 2 degrees. How is that case being covered i cant understand

»
10 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Isn't F1 too easy given its position and points.
$$$E$$$ $$$ \gt $$$ $$$D$$$ $$$ \gt $$$ $$$F1$$$

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it +6 Vote: I do not like it

    It isn't!

  • »
    »
    10 months ago, hide # ^ |
    Rev. 3  
    Vote: I like it +14 Vote: I do not like it

    Actually all testers virtual participate my round and only two VIP testers (around 3000 rating) solve F1. All the other testers including several red testers who has around 2600 rating failed to solve F1. So we thought F1 may be very hard and must have a difficulty of at least 2600, so we set F1 as 3250. However nearly 470 contestants solved F1 during contest, which were greatly beyond our expectations.

    • »
      »
      »
      10 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      I think it is because of the use of LLMs, really we can't judge the rating of problem now a days as it is possible a problem may be tough but easy for LLMS hence more solves and vice-versa

      Also, say one person solved a problem in a group of 5, with helps of LLM they can make sufficient changes in code to avoid plagiarism and within the contest time

      On my first read I too found F1 < D, but couldn't implement it perfectly which can be avoided. It really sucks...

      • »
        »
        »
        »
        10 months ago, hide # ^ |
        Rev. 2  
        Vote: I like it +12 Vote: I do not like it

        some platform coordinators require us problem setters to create problems that 1600 rating user can solve but even highest LLM cannot solve, which is nearly impossible today.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

As a participant, the problem C was fantastic! It really took me time to find out the conclusion and solve it. Good contest and tutorial!

»
10 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Can someone please explain why my code is correct? I’m a bit unsure after reading the editorial. My approach was to count how many times a number x appears on the left side and check whether the number on the right side is greater than x. I also attempted to remove k elements for a specific index i. Problem(C) https://codeforces.me/contest/2156/submission/345630175

»
10 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

Is it just me, or is C harder than D?

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

can anyone please make me understand the optimisation in the problem B, because the method i did was correct but i was getting TLE on that.

Here is my solution- https://codeforces.me/contest/2156/submission/345585986

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

W editorial

»
10 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Who is Katrina?

»
10 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

C was such a nice problem, ive nver seen one like it

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can any one help in getting intuition for the problem C ?

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In the bonus solution of B , i am not able to understand why there's a log^2 factor in it's time complexity instead of log??

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

345718528

Could someone explain why this is incorrect?

»
10 months ago, hide # |
Rev. 4  
Vote: I like it 0 Vote: I do not like it

can someone help me out with C: in the solution given , i dont know how he calculated the part not divisible by g , part he only find count greator than 4g what about divisibility part ? can anyone help me out ? here i did with brute force , finding both >4*i and numbers not divisible by i ( that can be relieved) i did brute force edit: understood

»
10 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

That was an amazing competition!

»
10 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

There's probably a typo in hint 3 of task E. Or maybe I misunderstood something?

This is because if there are any index i with $$$f_g(a,i) \gt 2$$$, Hao has to remove index i on his first move.

we need $$$f_g(a,i)≥2$$$ instead of $$$f_g(a,i) \gt 2$$$

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Guys would this solution still be efficient even if n<=10^5?

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Anyone solved problem-D using XOR properties?

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

F1 is so ez!
just go from x = 3 to n, and if(index[x] < idx[x-1] && index[x] < idx[x-2]) make the operation, because it always optimal.
and just make this loop n more times.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I have an alternative solution for problem E.

Hint 1
Hint 2
Solution
»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Are the solutions written by different people? I noticed that the solutions use different languages, and even for solutions in the same language, there are variations in coding styles. Some of the code styles are just too hard to ignore and I can't help but complain... Take the C problem, for example. Isn't the code a bit too compact? Where are the indentation and spacing? I know that seeking standardized coding styles in OI might seem a bit strange, but what on earth is #define int long long? Should this appear in a proper solution?

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Late to the party but can someone explain the solution of D. I got the gist of the solution but unable to understand 3rd and 4th paragraph of the editorial given. Why do we discard the elements that had different bits in the previous calculation?

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    Okay I got this. Also the editorial's 3rd and 4th paragraph could have been made a lot simpler rather than just confusing math. The thing is you filter out the numbers that have different last bit because they can't be the last Pn number because at least one bit is different. We will follow this approach till the highest bit and generate the number.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

C, D were very interesting questions. xd

»
10 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Can you explain B problem? How to escape tle?

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Every problem A-D except for B was pretty nice. Btw my n sqrt(n) solution for C passed lol

»
10 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Actually, I found an O(n) approach for problem E. First, we need to observe that the optimal answer can be achieved in no more than 4 moves. Define F(x, y) = b[max(x, y)] - b[min(x, y)] . Lets just assume there was two indices i and j where F(i, j) is maximized. Then, optimally, Hao would delete either i or j depending on frequencies of values in these indices (we don't care about it). Let's just assume j is deleted and i is remaining. Alex will lock index i. Next, define k as the second best index that makes F(i, k) maximized. Hao would optimally delete this index in his next move. Finally, define q as the third index that makes F(i, q) maximized. Alex will lock this index. Then, because Alex locked i and q, our best answer depends on neither which indices Hao erases nor Alex locks.

As in editorial, lets just say Hao will make the answer to be least of the answers for when Alex starts with arrays that some x is deleted. So, lets just focus on finding that indices which are worth trying. It turns out for some x we need two minimums in range [1, x - 1] and two maximums [x + 1, n], because Hao deletes no more than 2 elements. So, we just can precompute prefix minimums and suffix maximums, find the best index that the second best is maximized, and just try to delete this element, first minimum in range [1, x - 1], second minimum in range [1, x - 1], first maximum in range [x + 1, n] and second maximum in range [x + 1, n].

Total complexity would be O(n + 5n) = O(n). Here is my submission: 345943514

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hi, Can anyone please help me find problem with my solution for D,

Submission Link: Click here

»
10 months ago, hide # |
Rev. 5  
Vote: I like it +8 Vote: I do not like it

We can solve E without using binary search, here's my solution in O(n) 345998503

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Problem E. For the O(n) solution of E, one just needs to look at 3 possible first moves by P1.

First solve the simple game in which P2 chooses, P1 blocks, P2 chooses. The best strategy for P2 in this simple game is to choose the index that yields the second best payoff as P1 can block the first best.

P1 only cares to disrupt this best move. The three possible moves for P1 are to 1) pick the argmax of the simple game, 2) pick the other index that gives the first best payoff, 3) pick the other index that gives the second best payoff.

These are the only moves that disrupt the strategy of P2 in the simple game. Python submission

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can someone explain why this code is working for 2156A - Pizza Time

int n; cin>>n;
int m=n-2;
int c=1;
while(m>2){
    m-=2;
    c++;
}
cout<<c<<endl;

It performs around 10^11 operations in the worst case!!

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    If I'm not wrong , The O2 and O3 optimizations in GCC compiler optimize this to $$$\mathcal{O}(1)$$$

  • »
    »
    10 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Compilers will optimize certain statements, for example...

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int sum=0;
        for(int i=1;i<=10000000;i++)
            for(int j=1;j<=1000000000000;j++) 
                sum++;
        cout<<sum<<endl;
        return 0;
    }
    
»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I misread problem E at first, thinking the beauty was defined as min($$$b_j$$$ — $$$b_i$$$) instead of max($$$b_j$$$ — $$$b_i$$$). I couldn't make any progress on this changed version, wondering if anyone else has some ideas.

»
10 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

F2 is so fun but F1 is too easy.

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

why did problem B accept solutions where you go around the string infinitely until you make a=0 but after contest it does not accept that solution anymore?

»
10 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

orz

»
10 months ago, hide # |
 
Vote: I like it +1 Vote: I do not like it

"pizza time"

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

To make sure Hao eats as much as possible, he needs to keep the leftover group (m_3) as small as he can. Whatever is left over becomes the pizza for the next day. By picking the two smallest groups, (m_1) and (m_2), to be as big as possible, we limit (m_3) to at most 1 or 2 slices. This means the total amount of pizza decreases by about 2 slices each day. The game ends when there are only 1 or 2 slices left since no more splitting can happen. Therefore, the number of full cycles where Hao gets to eat is the number of times we can subtract 2 before getting to 1, which is (\lfloor (n-1)/2 \rfloor). Thus, the maximum slices Hao can eat is ((n — 1) / 2).

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For problem D, Hint 3 (and thus the solution) is incorrect (counterexample: n = 34, the sum in Hint 3 gets 69 >= 68).

»
9 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Regarding $$$F1$$$, in solution-1, why is it guaranteed that in next positions we will still be able to change them to their optimal values? Like when we keep updating some position until it reaches its optimal value, during this process, multiple values in the suffix will increment, so why something like this for example is guaranteed to not have a negative impact when we go to the next positions?

Also in the other solution of continuously picking the smallest number, I understand that in an optimal solution if we do 2 consecutive operations on disjoint element, where the first operation is on the larger value, we can swap them to make the small-value operation come first. But for the part of repeatedly reducing some value as long as we can, I understand this does not impact the prefix, but why is it guaranteed to not affect the suffix negatively in reaching its optimal?

»
5 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

i dont know about others but the editorial by very least on C is really bad.