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

Автор ch_egor, 8 лет назад, По-русски
Tutorial is loading...

(Разработка и идея — vintage_Vlad_Makeev)

Tutorial is loading...

(Разработка и идея — MikeMirzayanov)

Tutorial is loading...

(Разработка — cdkrot, идея — жюри)

Tutorial is loading...

(Разработка — Sehnsucht, идея — Андреева Е. В.)

Tutorial is loading...

(Разработка и идея — VFeafanov)

Tutorial is loading...

(Разработка и идея — Sender)

Tutorial is loading...

(Разработка и идея — voidmax)

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

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

Auto comment: topic has been translated by ch_egor (original revision, translated revision, compare)

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

Thx for fast judging and editorial!

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

Good problems, interesting solutions

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

Could D be solved using Topological Sorting?

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

C is very nice!

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

    Please explain the proof of C.

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

      There are already few comprehensive explanations, I don't think I can do it better.

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

        Given editorial for c problem is grt..!!..but what I wanna say is I got AC in different way(sadly not during the live contest)...initially I sort the array...pick the largest element & put it into the dequeue.. then in the same fashion I traversed back from (n-2) to (0) and at one move I pick the element & put at the leftmost position in dequeue( O(1) operation..) and in other operation I pick element & put at the rightmost element in dequeue... Through this I approach I got AC...but I m also surprised with editorialist's solution bcoz it is O(n) where my solution is O(nlogn)...but it works well in the given constraints

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

Can somebody explain how to do the Concatenation of lists in O(1) for problem F?

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

Anyone has done F I really need help with the problem. Plz help I just cannot figure out how can we find back the order of the numbers. I'm pretty new to C++ so solution in gnu C++ 11 -> 17 is fine for me. Thanks you guys a lot.

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

How to solve problem F using dfs? Many of the people have solved it using DFS.

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

Wait. On F, I don't understand why it's enough to simply unite the sets. We are trying to put the numbers on an ordered line, so when we unite a and b does it not matter if a is to the left of b or b is to the left of a? Can we prove that it doesn't matter? The editorial doesn't actually explain the problem, it explains how to do DSU.

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

Is there any way to solve F using DFS

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

How to solve G? I think I need more details.

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

didn't understand the solution of problem C, can anyone explain it to me or suggest other one ?

and what is the kind of topic he used to solve this problem ?

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

    The solution is a constructive one. Sort the sequence, and append all even-indexed elements reversely to the end of the sequence. Correctness proof is given in the editorial.

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

    I'll do my best to describe the proof in more detail:

    We have a problem that requires us to find a configuration that minimizes a value. The general approach used (which can sometimes be applied to other problems too) is the following: We prove that that there's a lower bound on how small the answer can be for a given input and then we figure out a configuration that achieves that exact lower bound.

    For this task: First, let's consider the numbers ordered such that a[i] ≤ a[i + 1]. We can then prove that the answer can't be better than ai + 2 - ai,  for any i = 1,2,3,...,n-2. ( statement 1 )

    If we manage to do that, then we can say that a lower bound for the answer is the maximum of all of those, i.e. max(ai + 2 - ai), where . The final step would be to see that the solution provided in the editorial gives that exact lower bound ( statement 2 ).

    Proof for statement 1: First imagine that you have a complete graph, where the vertices are the given heights and the edges represent the absolute differences between the two endings. In order to give a solution, we must give for every vertex a "before" neighbour and an "after" neighbour, such that we get a cycle going through all nodes exactly once (a hamiltonian cycle). Now let's prove by contradiction that the solution can't be better than ai + 1 - ai for a fixed i. Suppose that it is smaller. Since we want the maximum value of an edge to be stricly less than ai + 1 - ai, then it means we can't use any edge between a[m] and a[n], where (let this be the first set) and (let this be the second set), since a[n] - a[m] would be greater or equal to a[i + 2] - a[i]. From this, we can see that if we want to start a path from the first set that goes to the second set and then comes back, then we must use a[i + 1] at least twice. Thus, any cycle will contain a[i+1] more than once, so it can't be hamiltonian, so we can't build a correct configuration => contradiction with our initial hypothesis that there exists a solution.

    Therefore any solution can't be better than the mentioned lower bound.

    Proof for statement 2: I'll just mention the logic for the example solution given in the editorial: a1, a3, a5|a6, a4, a2. We can see that the difference between two heights in the first part or in the second is one of the those that give the lower bound. The other two are the difference in the middle and the one at the end. But we have that a[6] - a[5] < a[6] - a[4] < lowerBound and a[2] - a[1] < a[3] - a[1] < lowerBound. So the maximum of all values is less or equal to the lower bound, but since the lower bound is the lowest value, it means we get exactly that.

    Hope it helped.

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

Can anybody please point out why my solution for F is exceeding time limit? Thanks in advance!

50385034

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

G: Where is the case with dropping domino to the left? Also first formula shouldn't be dp[j]=min(dp[i-1]+c[i]) for all j, that j-th domino fall if i-th was pushed to the right?

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

I did Problem C using Binary Search, but my implementation was too complex 50403476. Anybody who also did it using Binary Search with an easier implementation?

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

DSU contest

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

How to solve problem G by dynamic? I need more explanation.

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

В чем проблема в моем решении F через DFS?

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

actually,I can't understand D's DSU solution.how to deal with '<'ans'>'?

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

    if aij equal to "=" then dish i from the first day and dish j from the second day must be equally good, then you will realize that 2 dishes must be on the same group. When you assign all dishes to the group then you can look at '<' and '>'. So if aij equal to '<' then the group of dish i from the first day are worse than the group of dish j from the second day so that makes a graph of the group of dishes, Same as '>'. After that use DFS on that graph to find which group are the worst and which one is better and so on.

    Here is my solution : link

    PS. Sorry about my English.

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

The following is another alternative for implementing the proposed solution for problem 1131C - Birthday.

50431644

Assuming a 0-indexed array a0, a1, ..., an - 1, and an array-size parity , your valid optimal solution can be formulated as follows:

ap, ap + 2, ap + 4, ..., an - 2, an - 1, an - 3, an - 5, ..., a1 - p.

P.S. In the problem statement, I think that the word "low" should have been written as "short", and that the phrase "growth of two neighboring children" should have been written as "heights of two adjacent neighboring children".

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

Can someone explain E more thoroughly?

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

The following is another intuitive deque-based solution for problem 1131C - Birthday, pushing ordered heights at both ends of the deque in alternation until all heights are pushed to form the optimal circle with minimum height-difference between adjacent neighboring children.

50471341

P.S. This idea was developed independently. Other contestants might have used a deque as well to form the requested circle.

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

Div2 Problem B: Draw! In my local machine, I'm getting the correct output for the test case, while on cf output is different, Can anybody help me with this, Here is my code .

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

    Try your original code on your local machine by entering the input values instead of copying the test case. It will output a garbage value. Solution: Replace mp(0, 0) by construct assignment pair<int, int>(0, 0). and mp(x, y) with pair<int, int>(x, y).

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

    In the second loop, i goes up to n,

    then in this line, y = min(arr[i+1].ff,arr[i+1].ss);

    You try to access the element at arr[n+1] which is some garbage value that you did not set.

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

Can anybody help me with the number assignment process in D?

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

Can you modify the answer fo G ? I think the editorial has a typo. The first situation should be domino falls left.

Thank you very much. I think it will be very helpful.

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

can anyone help me in question F. I used DFS. https://codeforces.me/contest/1131/submission/51000532

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

Given editorial for c problem is grt..!!..but what I wanna say is I got AC in different way(sadly not during the live contest)...initially I sort the array...pick the largest element & put it into the dequeue.. then in the same fashion I traversed back from (n-2) to (0) and at one move I pick the element & put at the leftmost position in dequeue( O(1) operation..) and in other operation I pick element & put at the rightmost element in dequeue... Through this I approach I got AC...but I m also surprised with editorialist's solution bcoz it is O(n) where my solution is O(nlogn)...but it works well in the given constraints

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

Just want to share my approach on F, don't Know how to use DSU or function mentioned but can be done using array of priority Queue, Might be a little complex and lengthy at first sight but simpler and easier

a Component=> a priorityQueue(element of priorityQueue array)

Priority queue is used to find element with least degree(0 or 1) in a component

also create a list to store neighbors of every element

there are 4 case when a new query comes.

1) both are included in different(obvious from question) components(can be checked by creating a map) then take the smaller Component and put all its elements to larger component while changing their location in map but before that to merge two components we need to update two elements each of each component changing their degree and adding them in each other's list

2) first element is included in some component then just add 2nd element in first element's group but before that update two elements each of each component changing their degree and adding them in each other's list

3) second element is included in some component , similar to 2nd case

4) no element is included in any component, put both element in new Component and mapping their location(index of their component) and add them to each other,s list

After that we have now a graph(actually a linked List ) , traverse the list to find one element with degree 1 and using that element as first perform dfs to print the array

https://codeforces.me/gym/252240/submission/60240365

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

In problem D , Otherwise assign numbers, where the vertex gets the least number greater than the vertex it goes to. how to do this??

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

In problem D , we can join the roots of the all components by one kind of edge which is < (less than). In other Words : if i is less than j we join i to j And if i is better than j we join j to i ( The opposite ). So now we have one kind of edge in the graph and we have to go through the edges and move from one component to other and we add one the component's counter (All the nodes in the same component will have the value of the component's counter). And we can only deal with the roots of the components using DSU . Code for better understanding : 62076560

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

Here's a solution to E that doesn't use associativity.

Consider 2 cases

Case 1: there are at least two distinct characters in $$$s_{n}$$$

Case 2: all the characters in $$$s_{n}$$$ are equal to some character call it $$$u$$$

Case 1:

Take a character that appeared in at least one of $$$s_{1},...,s_{n-1}$$$ call it $$$c$$$.

Let the string $$$t_{c} = s_{n} + c + s_{n}$$$

Then the answer will be the max beauty over all $$$t_{c}$$$.

Case 2

Let dp[i] denote the longest contiguous subsequence of $$$u$$$ in $$$((s_{1}\cdot s_{2}) \cdot \cdot s_{i-1}) \cdot s_{i}$$$

You can calculate dp[1] with two pointers. For dp[i] there are again 2 cases.

If $$$s_{i}$$$ contains a character other than $$$u$$$ the calculation is similar to case 1 replacing beauty with the longest contiguous subsequence of $$$u$$$

Otherwise dp[i]=(dp[i-1]+1)*(length of $$$s_{i}$$$) + dp[i-1]. (You place dp[i-1]+1 copies of $$$s_{i}$$$ around the longest contiguous subsequence of $$$u$$$ in the previous state)

The answer is dp[n]

code 105430189

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

How can we do C problem using binary search?