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

Автор Ormlis, история, 18 месяцев назад, По-русски

Спасибо за участие!

2024A - Выгодный процент придумала и подготовила Андреева Елена Владимировна при участии Artyom123

2024B - Покупка лимонада придумал Endagorion, а подготовил sevlll777

2023A - Склеивание массивов придумал и подготовил Mangooste

2023B - Пропуск придумал и подготовил adepteXiao

2023C - Ч+К+С придумал и подготовил yunetive29

2023D - Много игр придумал и подготовил Tikhon228

2023E - Древо жизни придумал isaf27, решил и подготовил Ormlis

2023F - Холмы и ямы придумал и подготовил glebustim при участии vaaven

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

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

Ormlis when will hidden test case and source code of others be visible?

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

Hi, I cannot prove my solution for div1D nor hack it I hope someone can hack or prove it.

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

i swear i can't figure out for the life of me why my solution to B isn't correct, and i'm not allowed to look at the failing test case either.

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

nvm

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

then $$$c_p \cdot q^{c_p} \gt (c_p - 1) \cdot q^{c_p - 1}$$$; otherwise, the smallest element can definitely be removed.

why?

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

    I also want to know "why?" Otherwise it's not a proof.

    My way of deriving same claim
  • »
    »
    18 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +32 Проголосовать: не нравится

    I did a similar claim, proves pretty much the same thing.

    Suppose we took an optimal subset whose weights sum up to $$$S$$$, and let's fix some $$$(p, w)$$$ taken ($$$p \lt 1$$$). Then optimality implies that the solution without this element, is not better. We can ignore the product of probabilities on both sides of the inequality and get:

    $$$S - w \leq pS \to S \leq \frac{w}{1-p}$$$. If we took $$$k$$$ elements of probability $$$p$$$, with differing weights, then denote by $$$w$$$ their minimal weight. So $$$S \geq kw$$$, and $$$w$$$ can be plugged in the inequality above to get $$$k \leq \frac{1}{1-p}$$$.

    The intuition behind the whole idea was easier for me to see in contest when I tried to bound the number of elements taken for $$$p = 0.5$$$, and certainly you won't take an element if it doesn't double your current sum.

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

C is a piece of dogShit,i mean why it had to be based on some crap observation.It could have been improved by giving a formal proof of why does that always work. Disappointed...

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

Ormlis In D2C, how can we solve the problem for arrays of sizes three or more? I tried to solve it by comparing inversions of ab and ba for sorting but it seems this condition is not transitive and thus doesn't work for arrays of twos either, so I had to use some other min/max technique, which doesn't seem to generalise for sizes more than 2.

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

got IGM but still cannot solve A during contest, isn't weird?

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

    A simpler solution for 1E:

    When you choose a node as the root node, our answer is at least $$$\sum_{i=1}^n \frac12 s_i(s_i-1)$$$, where $$$s_i$$$ is the number of children of node $$$i$$$.

    However, such a construction may not be able to satisfy some edges that pass through both the son and father at the same time. Let's consider the contribution of this situation to increasing the answer.

    We set a dp state $$$f_i$$$ to represent the number of residual paths that can be uploaded through the parent when the node $$$i$$$ calculates the necessary contribution internally (i.e., the above equation).

    Transfer as follows:

    $$$f_u = \sum_{v\in son_u} \max(1 - [u\text{ is root}], f_v - (s_u - 1))$$$

    After calculating $$$f_ {root}$$$, we must pair the extra paths pairwise, and when we choose the node with the highest degree as the root, we can prove that there must be a match to make the scheme valid:

    [tbd, prove is hard]

    So we can calculate $$$f_ {root}$$$ and add $$$\lceil\frac{f_{root}}2\rceil$$$ to the equation at the beginning.

    using translator.

    287001804

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

Is there a reason the submissions and testcases are still locked?

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

Samples on D1C are useless

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

I thouth Convex Hull Trick would work on 1D because they seems simular. But it didn't so I'm sad.

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

Here's my binary search approach for Div2 B:

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

I didn't understand D1C from the tutorial, can someone explain it in more detail

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

    A bit late, but here. Consider a cycle of length k in one of the two graphs. Enumerate the vertices along the cycle as the official solution does. So the first vertex gets label 0, second 1, and so on to k-1 which is connected to label 0. Imagine that the cycle branches at the node labeled 5.

    Because the graph is strongly connected if that edge is incident to vertex "e" then there must be a path from e to the node labeled 6 that does not use any edge more than once.

    (why? we have used only 5->e and by definition there must be a path between any two vertices. Any path from e->...->6 that includes 5->e can be done without it because it must include e->6 after it (e->...->5->e->...->6)).

    e->...->6 must have a length of a multiple of k because then we would have a cycle of length not a multiple of k.

    (why? We can go from 5->6 in 1 move, or we can go from 5->e->6 in |e->...->6|+1 moves. We know we have a cycle of length k through 5->6 so |0->...->5| = 5 and |6->...->0| = k-5-1 so |0->...->5|+|5->e->...->6|+|6->0| = lk. then (5)+|5->e->...->6|+(k-5-1)=lk then |5->e->...->6|=(l-1)k+1)

    So every path must conserve this coloring property and this is the only property required. (proof: collapse every node of the same color into a single node and conserve edges the only cycles remaining are of length k, longer cycles just represent going around this graph more than once).

    Now we can just add edges from k -> k+1 as needed to solve the problem.

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

I had different solutions for both div2 C and D

for C it's a completely different one, I used the following sort

sort(id,id+n,[](int lt,int rt){
            pair <int,int> lM = {max(a[lt].first,a[lt].second),min(a[lt].first,a[lt].second)};
            pair <int,int> rM = {max(a[rt].first,a[rt].second),min(a[rt].first,a[rt].second)};
            return lM < rM || (lM == rM && a[lt] < a[rt]);
        });

for D, Instead of building a graph I used a minimum segment tree to build the distance array so let's say we got d[i] = get(i,n), then we update seg(b[i],min(d[b[i]],d[i]+a[i]))

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

For Div2 C, I initially tried to sort any tuples by the following condition. Consider the two possible arrangements [tup1[0],tup1[1],tup2[0],tup2[1]],[tup2[0],tup2[1],tup1[0],tup1[1]] and in whichever arrangement the number of inversions is less I put that first. I got wrong answer on testcase 1123.I saw @Dominater069 also try to do the same initially. Can someone please explain why this solution is wrong?

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

    I had done the same thing initially. I suggest you read the following if you are not aware of transitive conditions for sorting.

    Exchange argument: Suppose there is a correct arrangement of the arrays. The editorial proposes a solution that says the arrangement created by sorting based on sum. We now only have to prove that any optimal arrangement can be transformed into the exact arrangement based on ascending sum, without worsening the answer.

    Transitivity: Now the condition of sum is transitive, i.e. sum(a) < sum(b) and sum(b) < sum(c) means sum(a) < sum(c). Now, if the correct arrangement has a pair of indices which doesn't follow this sum order, then we can argue that there is at least one adjacent pair such that they are out of order. The proof is simple. Assume there are non-zero number of elements between the closest pair of out of order pair, hence all the elements in between them are individually in correct order with either of them. Pick a random element x in between them. a < x and also x < b, so it must be that a < b, but we just assumed a > b. Hence the closest pair cannot have correct order elements in between them.Now when we flip the order of the two adjacent arrays, their ordering doesn't matter to the rest of array, but only on the relative order of the two adjacent elements which we show can be flipped without worsening the solution. We can keep arguing and flipping adjacent pairs until there is no pair out of order. Hence we can transform the correct arrangement to our preferred arrangement without worsening the answer.

    Since sorting by (min, max), (max, min) or sum are all transitive conditions, all of them have a similar exchange argument and are all correct.

    TL; DR: The count of inverse for ab and ba is not transitive and it cannot be guaranteed that the optimal answer will have adjacent out of order pairs (ordering based on Inv(ab) < Inv(ba)), if they are not adjacent then swapping them affects all the elements in between and thus it cannot be guaranteed to not worsen the answer.

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

      Such a nice explanation! I didn't actually think about how sorting works!. Thanks a lot. Here is a testcase for anyone else who will read this in future after having made the same mistake as me. [[3,3],[4,1],[2,2]]

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

      silly question please forgive and answer : how exactly did we show that swapping the 2 adjacent out of order pair will not increase the inversion between them ? is it just be trying some cases ? it's clear that it will not affect the left or the right part of the array but what about the 2 pairs them self ?

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

        yes it's casework only, and can be proven by brute forcing all possible cases. There is no general theorem regarding this, for example the order by summation heuristics becomes untrue for sizes starting from 3.

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

I feel like the test cases on D1C are quite weak because I just accepted it with a simple $$$O(K^2)$$$ brute force that checks if the two pairs of counting arrays are equal for any cyclic shift.

On the other hand, I assume it will be hard to generate such a test case if people construct the adjacency matrices and run DFSs differently because this will introduce some randomness in the resulting counting arrays, although that is not the case since most people just run DFS starting from vertex 1 (that is what I did in my accepted submission 287195742).

Was there an attempt to create some test cases against such an obvious brute force?

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

    Uphacked. Also, I think it's not hard to prepare a few of such cases with different "shifting" of the node numbers so that these "lucky" codes cannot pass. Since its average number of iterations would be something like $$$\cfrac{K^2}{4}$$$, it's very unlikely for them to run in the TL even for like 2 of such cases.

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

isn't constant C in problem 1D just $$$200000 + 1$$$, not $$$200000 \times \left( \frac{100}{99} \right)$$$

UPD: I think my claim is wrong, but it gets AC with $$$C = 200000$$$

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

Use brute force with O(K^2) time complexity to check the cyclic shift in Div.1 C can be accepted. Can it be proved right or just there isn't any hack yet.

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

Hacks to D1C have got Unexpected verdict. Ormlis can you check the validator?

link

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

    Yes, sorry about this. It seems we didn't have good tests against cyclic shift checking in O(k^2), and you hacked one of the solutions, that was marked correct in polygon.

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

2023D - Many Games There is statement $$$W\cdot (100 - p_i) \gt 200000$$$. It's not a simple one.

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

    About your analysis and your commentary about checking if something is minimum/maximum, you only need to check if $$$f"(x)$$$ is greater/lower then 0 at the points where $$$f'(x)$$$ equal $$$0$$$. This makes your analysis easier, as $$$f"(x)$$$ only assumes the sign required to be maximum overall $$$x \gt 0$$$. From this you only needs to compute $$$f(1)$$$ and $$$f(99)$$$ to check the inequality, removing the need to verify points with $$$f'(x)$$$ equal $$$0$$$ for $$$x \gt 0$$$.

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

In 2023B Skipping tutorial above, can anyone help me explain why we are allowed to do this "Now we are allowed to visit each problem as many times as we want"?

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

    It's because we defined the subproblem as we can move on to each problem, no matter if we already solved them or not.

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

      Thanks for your answer. But could you let me know why " no matter if we already solved them or not." In the problem description, we can not visit the problem which was previously submitted or skipped

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

        What you are mentioning is the constraint on the main problem, while this sentence is based on the subproblem that we just newly defined. We first solve the subproblem without the constraint, and then verify that the subproblem indeed solves the original problem.

        Once we solve the subproblem where we can visit the same vertex multiple times using shortest distance algorithms, we also know that it guarantees that each vertex is visited at most once (because visiting a vertex multiple times never helps with improving the shortest distance), so we see that it indeed does not matter if we're trying to visit the same vertex multiple times or not. Therefore, going back to the main problem, if we reach to a certain problem $$$i$$$ with the least penalty possible, we can then solve all unvisited problems with index $$$\le i$$$, receiving the prefix sum of the scores minus the penalty as the total score.

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

How do you generate such graphs for problem div1C ,or do you just originate all cyles from the same node.

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

Can someone pls tell why i got runtime error in pretest 4 for Div2 C , i sorted the array based on sum of elements
https://mirror.codeforces.com/contest/2024/submission/286970228

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

What's the necessary proof for D1C? Like if there doesn't exist some cyclic shift that satisfies, the answer is always false? And how to prove that?

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

What's the necessary proof for D1C? Like if there doesn't exist a cyclic shift so the frequencies are the same, then there's no solution? I think the editorial only shows sufficiency.

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

We can solve D problem (Many Games) faster. My optimization: for each element with p probability and w winning sum we can only choose winnings which sum we can improve.

Formula: x < p*(x + w) => x * (1 — p) < p*w => x < p*w/(1-p). x is the sum of set to which we can add our element.