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

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

1740A. Factorise N+M

Author: Pyqe
Developer: Pyqe

Tutorial

1740B. Jumbo Extra Cheese 2

Author: Pyqe
Developer: errorgorn, Pyqe

Tutorial

1740C. Bricks and Bags

Author: Pyqe
Developer: Pyqe

Tutorial

1740D. Knowledge Cards

Author: Nyse
Developer: steven.novaryo

Tutorial

1740E. Hanging Hearts

Author: Pyqe
Developer: tzaph_

Tutorial

1740F. Conditional Mix

Author: Pyqe
Developer: errorgorn

Tutorial

1740G. Dangerous Laser Power

Author: Pyqe
Developer: Pyqe

Tutorial

1740H. MEX Tree Manipulation

Author: steven.novaryo
Developer: steven.novaryo, Pyqe

Tutorial

1740I. Arranging Crystal Balls

Author: NeoZap
Developer: errorgorn, Pyqe

Tutorial
Разбор задач Codeforces Round 831 (Div. 1 + Div. 2)
  • Проголосовать: нравится
  • +128
  • Проголосовать: не нравится

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

I solved E it without using dp, if someone could prove why it works that would be great or maybe provide a counter testcase.

Approach

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

How to prove the first statement in the editorial for problem F?

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

    Well, the first thing that helps for this problem is to consider that all multisets have the same size, which is $$$n$$$. Simply, add additional zeros representing empty sets until you have $$$n$$$ numbers in the multiset.

    One possible way in which we realize that such a condition is equivalent and can prove it is to note the following: If we are able to createe a multiset $$$(M_i)_{i \in [0, n)}$$$ we can always move elements from a bigger set $$$M_i$$$ to a smaller one $$$M_j \lt M_i$$$ and still maintain a valid configuration. The reason is that in $$$M_i$$$ there are at most $$$M_j$$$ elements that are already in $$$M_j$$$, so the rest, $$$M_i - M_j$$$ can be moved to $$$M_i$$$ if it is necessary.

    This implies that if we consider the multisets sorted, which is what makes more sense, we can always move elements from $$$M_i$$$ to $$$M_{i+1}$$$. Thus, if a configuration $$$(M_i)_{i \in [0, n)}$$$ is valid, so is any configuration $$$(N_i)_{i \in [0, n)}$$$ with $$$\sum_{j = 0}^i N_j \le \sum_{j = 0}^i M_j$$$. And this is the key to the problem. We do not need to consider all multisets, only those that are maximal in this sense. And then we can count how many elements they have below them.

    By the way, once we get that formula, it makes no sense to keep considering the multisets in the way we are doing it. Instead, use the sequence of accumulated sums to represent the multiset. Then the condition becomes $$$N_i \le M_i$$$ for all $$$i$$$, which reads much better. Hence, our multisets are represented as increasing sequences $$$(M_i)_{i \in [0, n)}$$$ with decreasing $$$M_{i+1} - M_i$$$. Or even better, as increasing sequences $$$(M_i)_{i \in [0, n]}$$$ wiith $$$M_0 = 0$$$, $$$M_n = n$$$ and decreasing $$$M_{i+1} - M_i$$$.

    The question is, which multisets are maximal? Two multisets are not comparable if $$$N_i \le M_i$$$ and $$$N_j \le M_j$$$ for some indices $$$i$$$ and $$$j$$$. But... well, this was of little help for me. So, I thought: at the very least I know that the biggest lexicographically is maximal. Which $$$(K_i)_{i \in [0, n]}$$$ is the biggest lexicographically? Well, if we try to fit as many possible numbers in the first set, we will have $$$K_1 = \sum_{j = 0}^n min(\operatorname{cnt}_j, 1)$$$. Then, we will substract $$$1$$$ from every $$$\operatorname{cnt}$$$ and repeat. In the end, we get the multiset $$$K_i = \sum_{j = 0}^n \min(\operatorname{cnt}_j, i)$$$. (And the right hand side is precisely the formula of the statement. This, along with our previous observation, proves that the condition is sufficient.)

    However, now that I know the formula I also know that we cannot make another maximal multiset, because for $$$M_i$$$ we can only use at most $$$\min(\operatorname{cnt}_j, i)$$$ occurences of each number $$$j$$$. That means $$$N_i \le \sum_{j = 0}^n$$$ for all multisets $$$(N_i)_{i \in [0,n)}$$$. Thus, the lexicographically biggest multiset is, actually, the only maximal.

    Ending note: Yes, we can prove necessity from the very beginning and sufficiency if we consider the lexicographically biggest multiset and the first observation, without any notion of maximal elements. However, I am not sure one would get there magically. Instead, I believe the first observation must lead us to think of maximal elements and then we can either guess that there is just one or simply deduce it as it has been shown.

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

      Why do we get $$$min(cnt_j, i)$$$ in the formula for $$$K_i$$$ ? I get the part of $$$cnt_j$$$, but not the reason for the i. Is like we're telling we are repeating an element in one of the set we built right? but this should then be invalid

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

        Well, if you want to make each element the largest possible each time, you take one element from each set with one element, which is why $$$K_1 = \sum_{j \in [0,n)} \min(\operatorname{cnt}_j, 1)$$$. Then, you substract one from each set and get

        $$$K_{i+1} = K_i + \sum_{j \in [0,n)} \min(\max(\operatorname{cnt}_j - i, 0), 1),$$$

        because you took at least $i$ elements from each set already.

        Then, by induction, if you suppose $$$K_i = \sum_{j \in [0,n)} \min(\operatorname{cnt}_j, i)$$$, you get

        $$$ K_{i+1} = \sum_{j \in [0,n)} \min(\operatorname{cnt}_j, i) + \sum_{j \in [0,n)} \min(\max(\operatorname{cnt}_j - i, 0), 1), $$$

        which equals $$$\sum_{j \in [0,n)} \min(\operatorname{cnt}_j, i + 1).$$$

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

    You can conclude and prove this lemma with mincut maxflow — if you try to find a maximum matching between a chosen multiset of sizes, and the frequencies of the elements, then try to find the condition by which all cuts are of size at least $$$n$$$.

    It's pretty lengthy (I can elaborate if you want), but you can arrive at this condition without magically guessing it (the magic here comes from the magic of MCMF).

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

My logic is exactly the same as the editorial but giving WA at tc 2

sol link: https://mirror.codeforces.com/contest/1740/submission/178662191

can someone please help me... thanks

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

What is $$$k$$$ and $$$z$$$ in the first statement in the editorial for problem F?

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

In Problem E, can anyone explain why we would ever do this? ->If card i is used in the longest non-decreasing subsequence, then the maximum answer is the maximum value of dist(j,i) for all j∈Di.

Can someone give a small counter example where doing just this (->If card i is not used in the longest non-decreasing subsequence, then the maximum answer is the sum of dp values of all of the children of i.) will fail.

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

In my opinion, the editorial gives the conclusions more than proof or explanation for them, with many sentences like "We can observe/see/obtain/ that ...".

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

I think the time complexity in C problem would be O(nlogn) the writer forgot that he assumed that the elements are sorted . ( Though nlogn will do the work but still )

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

Imho, complexity of problem D is O(n). There is just iteration over an array.

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

In D, let's say we have the grid:

  • x 1 2
  • x 3 4
  • 5 6 x

where x are empty cells. If we can move any card to any cell, as long as there is an empty cell, could someone explain how we could move 4 to the cell where 5 currently is — cell with coordinates (3,1) ?

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

    You can't but you don't need too. Cards only move if they are the current next card going to the exit or as part of a rotation to let another card past (so you'd never need to move from one 2x2 square into the other). As long as there is an empty square any card can reach the exit which is all that matters.

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

      Can you please explain how you concluded that it is impossible to move 4 to the place of 5 following the rules, I tried alot but am not able to move 4 and empty space together in the lower left 2 x 2 square, maybe that is the reason its impossible ?, Can you please explain your conclusion.

      Edit : I got it, its just because the size of cycle for the rotation is odd so we cannot shift it, had it been even, we could have.

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

    Nice catch! We actually did not realise the possibility of that. The tutorial has been edited to have a more correct claim.

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

Very pleasant round to participate in. Liked E and F a lot. C and B were also pretty nice. Looking forward to see more rounds from you!

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

Did anyone solve problem I like this?

Start from editorial's O(nm^2) knapsack

Lets say you have dp[i] after considering $$$f_0,...f_{i-1}$$$. divide $$$f_i$$$ into $$$K$$$ line segments. let the kth segment is $$$a_kx+b_k$$$ for $$$l_k\le x\le r_k$$$

Then $$$dp[i+1][j]=\min_{0\le k \lt K}(\min_{l_k\le x\le r_k}(dp[i][j-x]+a_kx+b_k))$$$ can be calculated in O(mK) using deque or something to find range minimum

so in total it will be O(mn)

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

In problem E, why is ai>maxj∈Di(aj) true in the optimal solution?

Edit: Its clear now, thanks for editing the editorial

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

For que 5 I thought of a solution where the answer will be (no of nodes — no of nodes with more then one children). It fails on test case 6. Can anyone please provide a counter example, I am unable to think of one.

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

Animations like in D helps understand better

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

In problem F, I got AC by $$$O(n^3\log n)$$$ (Though it can be optimized to $$$O(n^2\log n)$$$ easily).

Too weak system test or too high efficiency?

Submission

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

A was really hard to believe its a CF question

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

editorial for C it's too long. my thought was like this: put all numbers in a set. if size of set is 1 or 2, it's easy to see the answer. otherwise, imagine the numbers are delimited by two indexes i and j, so if our set is a and |a| = m, then a1, a2, .. ai belong to bag x, ai+1, ai+2, .. aj belong to bag y and aj+1, aj+2.. a_m belong to bag z.

The dummy or brute force approach is to iterate over i and j to find the answer in O(n^2). The answer would be the max of min(bagz) — max(bagx) + max(dif of max(bagx) and the next one, dif of min(bagz) and previous one). as you can see, bag x or bag z can be the middle bag (bag 2) depending of the result of max(dif of.., dif of..).

I put the dummy solution here

dummy solution

to optimize this, I thought of doing binary search on second for but it wasn't possible. Tho I noticed that the ans at the end is max of 2*u[j+1]-u[i]-u[j] or u[j+1]-2*u[i]+u[i+1]. The key here is to see that on the first expression, to maximize you have to choose u[i] = u[0] (i=0) and just iterate over j, while on the second expression you choose u[j+1] = u[m-1] (j=m-2) and just iterate over i.

so finally the answer it's using two for. if the array initially was sorted, o(n), but cuz of set or sorting, nlogn.

336566747