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

Автор Vectors_Master, 19 месяцев назад, По-английски

We hope you enjoyed the problems! Thank you for participating in the contest! We would love to hear your feedback in the comments.


How did you find the contest?
Which problem was your favorite?
Which problem did you find the least enjoyable?


2071A - Игра никогда не заканчивается

Hints
Solution
Code
Rate the Problem

2071B - Совершенство

Hints
Solution
Code
Rate the Problem

2071C - Бесплатный сыр

Hints
Solution
Code
Rate the Problem

2071D1 - Бесконечная последовательность (простая версия)

Hints
Solution
Code
Rate the Problem

2071D2 - Бесконечная последовательность (сложная версия)

Hints
Solution
Code
Rate the Problem

2071E - Листопад

Hints
Solution
Code
Rate the Problem

2071F - Башенные массивы

Hints
Solution
Code
Rate the Problem
Разбор задач Codeforces Round 1007 (Div. 2)
  • Проголосовать: нравится
  • +181
  • Проголосовать: не нравится

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

very interesting problems!, thanks you all

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

Why is there no Hints on D???

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

How to come up with solutions for problems like C ? I figured en to be the last one in the permutation but couldn't progress further.

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

    practice makes perfect

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

      Obv, can you tell how you came up with solution for C ?

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

        I actually got the same solution as the editorial

        Basically, by past problem solving experiences, I tried rooting "en" because it was my target, so measuring how distant I am from it would be easier if it was the root because the distance will simply be the height of the current node

        Then it was trial and error, initially I though about climbing the tree and then take turns on each neighbor of the root, until after some time testing I realized that if I did this backwards (starting from the deepest level) would make it easy to predict my height

        Tbh the advice will always end up on "solve more problems" Like, rooting a node is a standard idea that you will see in many other tree problems, so at some point you expect this will help

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

        Reverse dfs

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

What is the solution for D1?? is it standard typre problem??

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

I am shocked to find out that the answer for C doesn't depend on st

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

https://codeforces.me/contest/2071/submission/308387650 why is my approach getting wa at tc 2 can anyone tell me what am i missing?

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

    Consider the tree 2<->1<->3<->4<->5 with st 3 and en 5. Your code would print it 1, 2, 3, 4, 5, since 1 and 2 are in rem and 3 4 5 are in ans1. The way the rat would move like 3 -> 2 -> 1 -> 2 -> 3 -> 4, failing to reach 5.

    The problem is that you are not printing the other nodes in order of their depth, but rather just the order of their number.

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

what an amazing solution to C!

i had a completely different solution.

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

    please share your approach

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

      Key Observation: If we start at a vertex x and perform a postorder traversal rooted at x, we get all the vertices in x’s subtree and we end up at x. This can be verified with examples.

      Solution Approach:

      we root at st, If we are at en, we perform a postorder traversal and add all visited vertices to our answer. Otherwise, we perform a postorder traversal from each node between st and en, but we exclude the subtree containing en. We keep adding the visited nodes to our answer. Finally, we move into the subtree that contains en and continue the process. By following this approach recursively, we obtain the required answer.

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

        can u tell like how did you get such a observation that for any subtree doing postorder will eventually lead to the current node itself . I had a stupid idea of first going to the target node and then keep choosing the leafnodes rooted at st . Idk what i was thinking . I thought of it as the push/pull kind of system .

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

          i had the idea because i observed if we keep take lower nodes first, then go up from there, we would ultimately reach up as specified in the official solution, but then i realized, doing postorder which also lead to same conclusion.

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

          you can visualize it with examples , its just that a reversed order

          of traversal will allow you to reach half the distance then comeback

          so if we take an example [1 , 2 , 3 , 4]

          Start at node 1.
          
          Cheese at 4:
              The mouse moves one edge: from 1 to 2.
          
          Cheese at 3:
              The mouse moves one edge: from 2 to 3.
          
          Cheese at 2: 
              The mouse moves one edge: from 3 back to 2.
          
          Cheese at 1:
              The mouse moves one edge: from 2 back to 1.

          therefore the solution is just process all the nodes that doesnt lead to the end node in a reversed order (so that you come back where you started ready to visit other paths) , and process the nodes that lead to the end node in a normal order

          you can also look at my code if you want https://codeforces.me/contest/2071/submission/308726433

          hope that helps !!

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

Will be added soon(

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

Love the problems thx guys (⁠。⁠♡⁠‿⁠♡⁠。⁠)

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

C was excellent. Really excellent.

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

what happened to D editorial

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

Great round ! The problems were well-balanced and had interesting ideas. Really enjoyed solving them, especially 2071B - Совершенство.

Thanks to the Setters and Testers for the effort :)

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

During the contest, I read task C incorrectly, which made it seem very difficult to me and I decided to skip it. I thought the mouse could NOT pass through en earlier during the process. Now I'm wondering, if there's any elegant and easy solution for this task, because the solution I was able to come up with doesn't seem simple.

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

    Just Use Post Order Traversal from the end point and print the order. IG it works because when you try to the solve from the end point you have limited nodes to work with like 1 distance from end node and then 2... and so on.

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

      No, I was talking about a modified version of the task(where mouse cannot pass through en earlier). This solution does not work in this case.

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

        one solution to problem C is, rooting at en and placing the cheese at one of the remaining leaf nodes (if en becomes leaf we avoid it) and keep doing until en remains. finally place at en.

        let R be set of remaining nodes on which cheese hasnt been placed. it happens that rat will always be present in R or neighbours of nodes in R. i cant prove it, but proof by AC.

        you can similary use this theory for the modified version. let SZ be sum of all subtress of children of en. and SZV be size of the child subtree in which en is present. if SZ — SZV >= SZV, you will always pass en and have some remaining nodes. for SZ — SZV < SZV, we can call alternatingly and make SZ — SZV = 0, then the remaining tree will be tree rooted at en, and subtree in which en is present only. for this tree you can use my approach to reach en at the end.

        point out if anything was "unclear"

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

I think this round is harder than the Edu round 1006, but at least the problem is interesting. My friend encountered serveral corner cases which made him crazy!

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

Thank you for the great problems! I really enjoyed problem C, it was very nice. For problem B, I used a randomized solution 308317488.

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

Why should we double n when we solve problem D?

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

I had tried a different solution than the editorial, for Problem C. You can root the tree at node st, and then start a DFS traversal from the root, while pushing back values in an answer list. Say current node is u, then 3 cases arise:

  1. subtree of node u doesn't contain the en node: then first visit all children, and then pushback u (post-order)

  2. u is the en node: then again, do post-order

  3. subtree of u contains en node, but u is not en node: then first visit all branches of the tree that don't have the en node, and then pushback u, and then visit the branch containing en node (in-order).

https://codeforces.me/contest/2071/submission/308386874

The basic idea is that, if you are standing at root of a tree, and you place the cheese in the order of post-order traversal for the nodes of tree other than the root, then in the end, you will end up at an immediate chid of the root, and then placing cheese at the root, will bring you back to root.

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

Sir's, round was so cool and problems are good quality, if you add 2 more hard problems round will be definitely a good Div1+2 :)

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

For problem C I have taken the root as en and then the post order traversal of that tree gives the permutation. Not sure why this is working. Can someone help in building the intuition behind this approach?

https://codeforces.me/contest/2071/submission/308378910

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

For c , My approach was that we are starting with node start , then we will have one and only path from start to end , lets use this path at the very last in permutation , it means that after performing all non final path edge (ie nodes that are not in this path) we have to land on starting node , but how to do this ??

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

This might probably be the simplest solution to problem B (although very tough to come up with):

  1. First, ensure that n * (n + 1) / 2 is not a perfect square, as mentioned in the editorial (I personally used binary search. Had to use unsigned long long).
  2. After that, print all numbers from 1 to n, except the number 4. Swap 1 and 2 because 1 is a perfect square.
  3. Put 4 at the end of permutation. Done!!

I verified the solution by confirming that for all n from 5 to 5e5, (n * (n + 1) / 2) — 4 is not a perfect square. You can have a look at my submission here

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

Also in problem B if $$$\frac{n*(n + 1)}{2}$$$ is not a perfect square you can just generate random permutations submission

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

2071D1 - Бесконечная последовательность (простая версия) can anyone tell me in D1 why n is needed to converted to odd . please explain the solution to me.

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

Is it just me or B seems easier than average Div 2 contests cuz I usually take 1 hour to do this problem but for some reason, I did this B in 20 min

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

My solution for D2.

First, check the editorial of D1.

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

Alternative solution for B

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

For problem E, a vertex becomes a leaf if it is connected to exactly one edge. But in the editorial, for the third category all the neighbors are being removed. How would the vertex become a leaf with zero edges connected to it?

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

    Thanks for catching this mistake, exactly one of the neighbours must not fall. Fixed.

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

      In the solution of problem E in order to calculate contribution2(u, v) you separate it to two cases: when u and v share a neighbor s,

      1. All neighbors of u and v are removed except for s
      2. s is removed and all but one of the neighbors of u and v are removed

      In the editorial, the value for the second case (2.) is

      $$$(1 - fall_{u})\cdot(1 - fall_{v})\cdot(1 - fall_{s})\cdot e_{u}\cdot e_{v}$$$

      However, $$$(1 - fall_{s})$$$ implies that s is not removed from the tree. Should this not be $$$fall_{s}$$$ instead? Thus, I think (2.) should be given by

      $$$(1 - fall_{u})\cdot(1 - fall_{v})\cdot fall_{s}\cdot e_{u}\cdot e_{v}$$$
»
19 месяцев назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

I think there is a mistake in E's editorial (I might be wrong).

In the second category, u and v can share a common neighbour, but we need to calculate the probability that they become leaves whilst also having the common neighbour falls (it can happen that a neighbour of u doesn't fall (other than s) and a neighbour of v doesn't fall (other than s) and s falls and all other neighbours of u and v fall.

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

(x+1)^2≤y^2 in problem B shouldn't it be ? (x+1)^2 > y^2

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

A video tutorial for E . Let me know if you have any feedback!

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

I didn't understand the editorial for D2, could someone explain it?

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

    I didn't understand the editorial either, especially the 1 mod 4 part but here's my solution:

    There are two key high level ideas used here. 1. whenever asked about ranges try calculating prefix sums. (This is highly useful in digit dp problems) 2. 1^x = 1-x if x $$$\in$$$ {0,1}

    now first observe nature of P (the prefix xors)

    for i > 2*n+1 you have BASE^$$$A_{2*n+2}$$$ , BASE, BASE^$$$A_{2*n+4}$$$, BASE .. (Notice how only even indices of A are used here!)

    where BASE = $$$P_n$$$ ^ $$$A_{n+1}$$$ (if n is even) and $$$P_n$$$ (if n is odd).

    now observe the nature of A

    for i > n you have $$$A_i$$$ = $$$P_{i/2}$$$ so for some 2*k > n $$$A_{2*k}$$$ = $$$A_{2*k+1}$$$ = $$$P_{k}$$$

    so if you're asked for the prefix sums of A -> you're actually asking the prefix sums of P for half the length. (This should brighten a bulb inside you which screams log(n) )

    now if you're asking to calculate the prefix sums of P upto k you realize its some recomputable term upto 2*n+1, and after that you alternate between BASE and BASE^(even term of A). you can count the number of BASE that would appear upto K and add it up and what's left are BASE^$$$A_{2*k}$$$ terms.

    since you know after n : $$$A_{2*k}$$$ = $$$A_{2*k+1}$$$ = $$$P_{k}$$$ you can use this to write down the prefix sum of A as a function of the sums upto n, the sum of even terms and odd terms after n. and this gives you a way of computing the sum of even terms !

    you now have all the recipes for your solution. when asked about prefix sum of A upto k => you ask what's the prefix sum of P upto k/2 which asks the sum of even terms upto k/2 and so on. The trick for computing sums where each term is xor'd with BASE when BASE = 1 is : term^1 = 1 — term.

    I leave the implementation details for you to figure out but here's my submission : 308654304

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

could someone explain the jiangly's solution to problem F?

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

If you need to eat as much cheese as possible for question C, is there a solution?

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

    even tho , the solution will be the same , no ?

    As you can only move one edge per cheese location thus you can only collect half the cheese

    in a certain path , as you need to comeback for visiting other paths

    correct me if i am wrong !

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

      If the node where s is located has a large depth, should it be put into the subtree of s according to the depth first?

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

        i dont exactly understand what you mean by S ,

        i think cause of the traversing constraints of the problem , you can only

        collect half the cheese at each path (where en node is the root) , it

        doesnt really matter how deep that path is ,

        For example if this is your path 1 -> 2 -> 3 -> 4

        that should be the cheese distrubtion

        Cheese at 4: The mouse moves one edge: from 1 to 2.

        Cheese at 3: The mouse moves one edge: from 2 to 3.

        NOW you are gonna start collecting the cheese on your way back

        Cheese at 2: The mouse moves one edge: from 3 back to 2.

        Cheese at 1: The mouse moves one edge: from 2 back to 1.

        this cheese distribution permutation is pretty much needed as it is the only one that guarntees ending at en , any other permutation is risking going too deep into a path

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

          I'm sorry, I'm not very good at English, I mean whether a different starting point will lead to a better result for a different arrangement of nodes of the same depth, or an arrangement that can go back to the end point if it doesn't exactly follow the order of depth priority

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

In the editorial for F, in Elaboration, shouldn't the maximum "increasing" p-towering subsequence will look like this after processing 10th index: [6,3,8,5,7] (3 will be included as well, right?)

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

How to calculate $$$e$$$ in D2?

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

    The sum over even-indexed elements in the range $$$[n + 1, \lfloor \frac{m}{2} \rfloor]$$$ is defined as:

    $$$ $$$
    $$$ e = \displaystyle\sum_{\substack{n \lt i \leq \lfloor \frac{m}{2} \rfloor \\ i \text{ even}}} a_i = a_{n+1} + a_{n+3} + \dots + a_{\lfloor \frac{m}{2} \rfloor}. $$$

    To compute this efficiently, we utilize the recursive function $$$\text{sum}(\lfloor \frac{m}{2} \rfloor)$$$ that returns two values: the sum of even-indexed and odd-indexed terms up to $$$\lfloor \frac{m}{2} \rfloor$$$. To exclude terms before $$$n + 1$$$, we subtract the prefix sum of even indices up to $$$n$$$:

    $$$ $$$
    $$$ e = \text{sum}(\lfloor \frac{m}{2} \rfloor)_{\text{even}} - prefix_{\text{even}}(n). $$$
»
19 месяцев назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

I think D2 can be solved even if we allow array values to be up to 1e18, something like this https://codeforces.me/contest/2071/submission/308895384

since the sum of the interval to find can exceed long long limit maybe we could find mod of the value?

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

for B, you can simply find the values (say k) that such 1 + 2 + 3 ... + k is a perfect square (there are only a few). You can avoid this subarray by swapping k with the number ahead of it, ie making the sequence 1 + 2 + 3 ... k-1 + k+1 + k. If theres no "next" number, the answer is -1.

Like this

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

All you need is attention.For C,just dfs from en and output the index when backtracking.I found this after a long thought.

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

C with Topo sortsubmission link

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

problem E can be solved with a simple re-root dp: 343755312