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

Автор awoo, история, 6 лет назад, По-русски

1380A - Три индекса

Идея: BledDest

Разбор
Решение (Ne0n25)

1380B - Универсальное решение

Идея: adedalic

Разбор
Решение (adedalic)

1380C - Собери команды

Идея: Roms

Разбор
Решение (Roms)

1380D - Берсерк и Огненный Шар

Идея: Roms

Разбор
Решение (Roms)

1380E - Слияние башен

Идея: Roms и BledDest

Разбор
Решение 1 (BledDest)
Решение 2 (pikmike)

1380F - Странное сложение

Идея: Roms

Разбор
Решение 1 (pikmike)
Решение 2 (Roms)

1380G - Круговое подземелье

Идея: BledDest

Разбор
Решение (pikmike)
  • Проголосовать: нравится
  • +135
  • Проголосовать: не нравится

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

Fastest editorial for an educational round I think.

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

Fastest editorial for an educational round I think.

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

Btw, in E merging without “smallest to biggest” optimization somehow passes the tests :)

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

    Nothing surprising. There is even such a heuristic: randomly connecting sets. It works for O(nlog(n)).

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

      Oh, that makes sense, thanks

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

      No it's not $$$O(n \log n)$$$. Let's say we have $$$n$$$ one element sets and in $$$i$$$-th round we merge $$$i+1$$$-st set to su of first $$$i$$$. Then on $$$i$$$-th turn we have $$$\frac 12$$$ probability to do one insert, and $$$\frac 12$$$ to do $$$i$$$ inserts, which means on avearge $$$O(i)$$$ inserts on $$$i$$$-th turn, which adds to aveeage of $$$O(n^2)$$$ inserts.

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

        That's one way to look at the probabilistic formulation. If you have broader probability space, for example, if operations are also chosen randomly, then the probability of big set being in the operation can be small, and I think it won't be O(n^2). I'm not sure how to show it, but my solution passed in the beginning, until they added a counterexample as yours, so if tests were generated using random at first, I think it shows that average complexity is not so bad.

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

I am not able to convince myself that if there is some answer, we can find an index j such that aj−1aj+1 ? Can anybody explain it better maybe :)

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

    If you are asking about A, then:

    Take ai < aj > ak

    Lets shrink the distance between i and j. If i = j — 1, its done. Otherwise if aj < a(j-1), do j = j — 1, its still correct solution, and continue the loop. Otherwise take i = j — 1, and exit the loop, so we’ve done that.

    So if there exist a solution, then there is a solution with i = j — 1. Take the set of such solutions and take with the smallest distance between j and k. If it is not one, then all elements between j and k are greater than aj. But then we can take i’=j, j’=j+1 and k’=k. So its distance is smaller then that is a contradiction

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

Мне кажется, что в разборе задачи D есть опечатка. Это:

поэтому при l<x и r<x решения нет. Нужно заменить на: поэтому при l<p и r<p решения нет.

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

В любом случае спасибо за раунд и быстрый разбор!)))

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

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

In the solution of problem E, visualising the towers and its merged states as tree is quite impressive. Thanks for the LCA solution.

To me, Small-to-large merge sounds like a greedy approach. It would be helpful if you can elaborate the alternate solution.

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

    If you are looking for dsu solution.... If you always merge smaller set to larger set then it is o(n log(n))... Because a single element will not change it set more than log(n) time..... Let say we have a element 'a' which is in set 1 of size x we merge set 1 to set 2 of size greter than x suppose y.... Than we have atleast 2*x element which get in same set as y>x..whenever we are merging we are atleast doubling the size of. set

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

Statement of problem B was difficult to understand until watching the image at last as didn't know about the game.

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

Can anyone explain to me why greedy works in C? It was kind of intuitive to me, I coded it up and it passed but I still can't figure out that why's it optimal?

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

I don't understand problem-B.Anyone help me to understand..And I don't know about this game.

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

Why are submissions low on problems? Were they hard, imo first 3 were pretty easy?

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

Why are submissions low on problems? Were they hard, imo first 3 were pretty easy?

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

problem G. 'Let the values be x and y. If they differ by at least 2 (x≤y−2), then the smaller result can always be achieved by moving a regular chest from the larger one to the smaller one.' I could not understand the proof below. I indeed turn a coefficient y into a smaller one (x + 1), but how can I assign every regular chest to the old value, with the changes of this two interval lengths?

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

Can someone explain why the second solution for problem A works?

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

Can someone explain in problem B why picking the greedy ci for the most frequent will somehow work for the rest of string?

How does that make sense? Can't there be a value in the string where ci fails?

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

    Your choice string is played agains the given string on every position. This means, all positions of the two Strings are paired once. Or, in other words, it does not matter in which order you put the symbols into the choice string.

    Since the order does not matter, every single position in your string conributes independend of any other position. Finally, for a single position it is obvious that the best choice is based on the frequency of the symbols.

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

My Video Solution of B and C where i have tried to explain my thought process and why the solution worked .

»
6 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится -6 Проголосовать: не нравится
hi,
problem D:
how to select a segment?
like for k=3,x=1,y=100,n=9
a=1,2,2,3,3,3,3,3,4
b=1,3,4
»
6 лет назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

in question E merge towers: for the given test case [[5,1],[2],[7,4,3],[6]] are the towers before any query on merging tower 1 and 3 according to me it should be done like: from tower [5,1] ,1 goes to tower 3-> [5],[7,4,3,1] -> 1st operation from tower [7,4,3,1] , 1,3 and 4 goes to tower 1 -> [5,4,3,1],[7] -> 2nd operation from tower [5,4,3,1], 5,4,1 and 3 goes to 3rd tower -> [],[7,5,4,3,1] -> 3rd operation it can be done in three operation but it shows 5 as a result . Where am i wrong?

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

    Put some clothes on and format the question ;)

    The result must be one tower [7,6,5,4,3,2,1]. Somehow you are loosing the 2 and 6.

    The rule for merging is fairly simple: Take the top segment from the tower where the 1 is, and put the whole segment onto the tower where it fits. The moved segments in the example would be:

    [1]
    [1,2]
    [1,2,3,4]
    [1,2,3,4,5]
    [1,2,3,4,5,6]
    

    The last move creates the complete tower.

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

We can also solve F by matrix-DP .. First we calculate the matrix for every dp transition .. then we just need the product of these matrices .. (To simplify append 0 at the begining and 9 at the end ) and build segTree in [0,n] and then remains only two point updates at index(x) and index(x-1) .. (Make sure to have dp[n+1]=1 (even if its nine ))

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

.

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

There's another solution O(n) for A.

  • As per the given condition, we can see that the element with value n will definitely satisfy this condition as middle element and the ends of the array as first and last element. (Because n will be bigger than anything and that's what we want here).
  • If n is at the ends of the array, then n can't be the answer. We ignore that element, update ends of the array and do the same thing again. The highest element in the array is now n - 1 and if it's somewhere in the middle, that should be the answer.
  • We'll keep trying the same for all elements and we'll know if the answer exists at all.

86668426

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

can anyone please explain what is this line doing in problem D solution res += (len - k) * y + x; . this line will be executed when we cannot perform berserk because one of the elements in segment is greater than both l and r and cost of berserk is lesser than fireball to delete everything. i thought this should have been res+=len/k*x so that we delete everything remaining using fireball. Thank you!!

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

    The tutorial does the operations in irritating order. However, if the biggest monster is bigger than l and r we need to use Fire at least once. And independend of anything else, we need to use Berserk on at least len%k elements. The order of these two operations or the others operations does not matter.

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

In problem G why can we ignore the initial order of chests and sort? I was thinking on a case like 4 40 400 400 600 and k=1. Where can I put the mimic so that the answer gives 330 (as it does with the editorial solution)?

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

    You misread the problem: "Print n integers — the k -th value should be equal to the minimum possible expected value of players earnings if the chests are placed into the rooms in some order and exactly k of the chests are mimics."

    "the chests are placed into the rooms in some order and exactly k of the chests are mimics." so you can choose any order.

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

In B ,what if there is an extra constraint that "You will lose point if the bot's choice is superior",So doing the same thing which we actually did for the original problem,would it be still optimal ?

For Ex :"RRSP" ,and output "PPPP",
Win(1),Win(2),Win(3),Win(4)= (+1)+(+1)+(-1)+(0) = 1;
Avg = 1
  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    It is still the case that every position is played against any other position. So the order of the symbols in the choosen string does not matter. Since the order does not matter it is still optimal to use one symbol for the whole string. As a pragmatic solution, just try all three possibilities and choose the best.

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

Anyone please explain the update part in problem F .
how we are doing updates ?

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

Just curious:

Does there exist some kind of dp solution for D?

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

    Constraints are too high for a DP solution for problem C(assuming you mean by DP is to brute force and use dynamic programming to decrease number of total operations made).

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

    Disclaimer: It is a little messy because I tried to code as fast I could and submit it during contest.

    Here you go! 87810909

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

problem C is enjoyable

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

86766761 Can someone help me identify what did I do wrongly here on problem C?

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

    If you start small, you are guilty of waste. M = 8, for example,,2,7,7,7,7,7,7 [1]; Instead of [7.7][7.7][7.7] [7.7] As for the answer greater than correct, if m=10,[4,4]; You only need 10/4=2, but (10/4)*2=8 does not equal 10

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

In C I miss read the question and was thinking that each team should have a product at least x. can anyone tell how to solve if this was the question ??

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

Can anybody help me with Problem D Berserk and Fireball I am facing some implementation issues? My submission — 86799781 Thanks

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

upd:done

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

awoo can you explain what 0,1,2,3 represent in the solution of problem F. Thank you.

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

@pikmike Can you please explain me the problem -e test case when we merge the 3 and 1 tower how the ans coming out to be 4 instead of 3 . Ok I can tell you how i got 3.

1st tower contain — 5 1 and 3rd tower contain — 7 4 3

1st move — you shift (1) from tower 1 to tower 3 now 3rd tower contain — 7 4 3 1 and 1st tower conatin — 5

2nd move — you shift (4 3 1) from tower 3 to tower 1 now tower 3 contain -7 and tower 1 conatin — 5 4 3 1

3rd move — now you shift (5 4 3 1) from tower 1 to tower 3 now tower 3 contain — 7 5 4 3 1 and tower 1 conatin nothing .So my answer coming out to be 3 instead of 4 . I know i am missing something could you please point out.Thankyou.

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

    Reread the problem statement carefully.

    We are not calculating the number of operations needed to merge the towers in the query. Instead, after each query, we want to calculate the number of operations required to merge all current towers into one.

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

In problem E it is not at all clear how to achieve these answers.

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

I have tried to make editorial for questions A-E . please have a look. Language :- Hindi

https://www.youtube.com/playlist?list=PLrT256hfFv5UUIBTJBUL7ZlZVHaWWEmGB

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

Was F inspired by this meme?

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

I still don't understand the tutorial for F.

Specifically, I don't understand how a segment tree could optimize this dp. What will the nodes store and what the merging looks like. I get the part about the dp but become totally confused when they start talking about segment tree.

Can anyone explain it for me? Maybe some visual example would help. Thanks in advance.

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

There is also a surprising O(N*loglogN) solution for problem A. It uses DSU with both path-compression and small to large do to the merging in O(N*α(N)) and then since the small-to-large merged tree has at most logN layers, LCA and binary lifting can be done in O(N*loglogN).

Submission: https://codeforces.me/contest/1380/submission/365834839