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

Автор Vladosiya, история, 3 года назад, По-русски

1881A - Не пытайтесь посчитать

Идея: Vladosiya

Разбор
Решение

1881B - Три паутинки

Идея: Gornak40

Разбор
Решение

1881C - Идеальный квадрат

Идея: myav, MikeMirzayanov, Vladosiya

Разбор
Решение

1881D - Уравняй делением

Идея: myav

Разбор
Решение

1881E - Блоковая последовательность

Идея: MikeMirzayanov

Разбор
Решение

1881F - Минимальное максимальное расстояние

Идея: ibraevdmitriy

Разбор
Решение

1881G - Аня и таинственная строка

Идея: Gornak40

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

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

I just have a question: Why is the algorithm for F correct? What's the intuition behind it?

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

"the author is lazy"

Pretty obvious from the way this editorial is written

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

For problem 1881F - Minimum Maximum Distance , can someone please tell the proof why it is always true to consider the longest distance between the labelled vertex and then divide it by 2 then take ceil of it.

After considering some examples it becomes somehow convincing but not very intutive about why that condition will always be true.

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

    Define $$$dist(i,j)$$$ as the distance between node $$$i$$$ and node $$$j$$$.

    Assume that there are $$$3$$$ labelled vertices $$$a,b,c$$$ and $$$(a,b)$$$ is the pair that creates longest distance from two labelled vertices. To find the node position that makes the minimum value of maximum distance to either $$$a$$$ or $$$b$$$, ofc we choose the node (call this node $$$d$$$) that resides in the middle of the path from $$$a$$$ to $$$b$$$ (since if without loss of generality we assume $$$dist(d,a) \leq dist(d,b)$$$, then $$$dist(d,b) = \bigg\lceil\frac{dist(a,b)}{2}\bigg\rceil$$$ is the maximum from both and this is the min value of $$$dist(d,b)$$$).

    Now, suppose $$$dist(d,c) \gt \max(dist(d,a),dist(d,b))$$$. Then, the longest distance from two labelled vertices must be the pair $$$(c,a)$$$ or $$$(c,b)$$$ (since $$$dist(d,c)+dist(d,b) \gt dist(d,a)+dist(d,b)$$$ and $$$dist(d,c)+dist(d,a) \gt dist(d,b)+dist(d,a)$$$) which results in contradiction.

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

C was the coolest one and it's not even close

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

Starters were bad(ABC) but the main course was good(DEF) but i am not able to understand the bill(editorial)

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

    tru, i dont really enjoy ABC this round. DE was kinda meh for me. FG was quite interesting to play around with

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

      can you explain to me why in E we are updating dp[i] as

      dp[i]=min(dp[i+1]+1,dp[i+a[i]+1]) and not as

      dp[i]=min(dp[i+1]+1,dp[i+a[i]+1+j]+j) for all j st i+a[i]+1+j<n indexing from 0.

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

        Depends on how you define your DP. My design was that dp[i] = minimum removals I can have after considering all the values from [i, n — 1].

        Case 1: We don't take the current index.

        That means that we will need to remove this index. So, dp[i] = min(dp[i], dp[i + 1] + 1).

        Case 2: Take the current block.

        That means that we will need to remove all the values from [i, i + a[i] + 1]. So, dp[i] = min(dp[i], dp[i + a[i] + 1]). Need to make sure it is not out of bound. You can only end up at i + a[i] + 1, nowhere else.

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

          I am saying that when you take the current block, it means you will take a[i] number of elements with you and then consider the next block. So I am saying that we pop some more values before taking the a[i] values and it can land us an even better solution. Thats y i am checking for all j possible

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

Task D

If we assumed 1s can calculate 10^8 times, but in the worst condition(all a are equal to 999983), it will judge near 2000(t)*10^4(n)*10^3 times. Would it TLE?

I am a novice and thank you for your generous advice and point out my mistakes.

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

https://ideone.com/lyUPEZ

problem F c++ BFS code: why RTE on test 3 ???

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

    Ok let me show some potential improvements of your code:

    Why you are wrong: You missed out the corner case (n=1) where deg[1]=0 meaning your "start" is undefined and therefore shows runtime error. Meanwhile, the solution is wrong(after I tested it with the fixed code).

    Data Structures used: You dont need to push the k values into a set instead use a boolean vector or smt. set requires O(nlogn) which means you will waste precious time if you are using set.

    Your code checks if the root is in the set and the adjacent elements as well, you can generalise it by putting it after int node=q.front(); q.pop(); if(bla bla bla) mdis.push_back(...). You can save some lines of code.

    You can try learning how to write functions such as function<void(int)> bfs=[&](int root){ code here}; this allows you to write the function inside your main fucntion where you dont need to pass all the arrays and stuff. You can access it inside the function. This should save you some implementation time as well.

    Your code is not very clean (for a guy like me), therefore hard to read. I saw some parts of the code that has strange spacing. I used to be a template monster with around 400 lines of templates, but I find it hard to debug if I write a code with lots of shortforms(for some reason). I recommend spending sometime either looking at other people's code and learning a neater way of writing it. I'm not pinelizing you, just giving some personal suggestions

    Neater and fixed code(although it is wrong): Sorry that I deleted the front part of your code.

    code is here: https://ideone.com/fN9WEY

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

I lost the top 150 due to hacking task D :(

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

Simple and insightful Video Editorials for A-E.

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

Why is my code for incorrect? I feel like it closely resembles the intended idea. It's prob D. Please help me My code

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

For F, It's always better to re-construct the tree like this.

Tree

It's related to tree diameter (I guess there's no formal proof but this blog will help Blog)

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

Can anyone please explain how does D solution works? Can't able understand how counting frequency of prime divisors gives our answer.

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

    Let's use two ideas:

    1) Every number can be represented as a product of prime numbers (= prime divisors). This is known as factorization.

    2) If two numbers are equal, they have the same set of prime divisors.

    So, the operation in the problem allows you to "take" one prime divisor from a[i] and "give" it to a[j].

    If, after doing this operation several times, we can rearrange the divisors so that every number in the array has the same set of divisors, then the answer is YES.

    To check that this is possible, we can simply count the number of occurrences of each divisor in the products.

    For example, consider test case 4:

    4

    30 50 27 20

    30 = 2 * 3 * 5

    50 = 2 * 5 * 5

    27 = 3 * 3 * 3

    20 = 2 * 2 * 5

    We have four occurrences of "5", four occurrences of "3" and four occurrences of "2". By doing the operation several times, we can turn each number into 2*3*5.

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

Only AC 1 problem... f**k me

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

If someone prefers video explanations or interested in knowing how to think in a live contest or reach to a particular solution.
Here is my live Screencast of solving problems [A -> E] (with detailed commentary in Hindi language).

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

Can G solved with sqrt-decomposition?, I'm getting WA2 Code

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

the editorial is short and to the point!!

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

.

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

Problem F solutions are based on the tree diameter, It takes some greedy proofs but in the end you can convert the problem to a direct tree diameter problem. Here's a blog

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

Any one Feels that this contest was not for Div.3 ?

It seems to be Harder :(

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

How do I solve 1881G - Anya and the Mysterious String with Segment tree using Lazy propogation? This is what I've done 227967016, I haven't used Lazy propogation and it's TLE. Thank you in advance.

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

Why this code doesn't work for problem D?

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

I feel it was really a nice contest for anyone starting out on cp in the sense that it offers a good mix of adhoc and dsa

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

Имеется вопрос. Как я понимаю, на этом раунде задачи сразу проверяются на всех тестах. Тогда почему через день после раунда вердикт задачи B с "Полного решения" поменялся на "Неверный ответ на тесте 18"? Типа добавили новые тесты на некоторые задачи?

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

f can be solved using dp Let define d(v) as the max distance from vertex v to a labeled vertex in its subtree and define g(v) as the max distance from vertex v to a labeled vertex which is not in the subtree of v then d(v)=max(d(child of v)+1), g(v)=max(g(parent of v)+1,d(sibling of v) + 2) then f(v)=max(d(v),g(v))

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

F is similar to

The only change is to fix the end points of the diameter as RED nodes.

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

I did rerooting for F, would've gotten top 100 or something but I had to have a typo that I didn't see

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

I have two nicer(?) solutions than the official ones.

B: Suppose everything has length $$$l$$$ in the end. Then $$$l \mid A$$$, $$$l \mid B$$$, $$$l \mid C$$$ (proof: run the splitting apart in reverse). This is also sufficient, and uses $$$\frac{A}{l} + \frac{B}{l} + \frac{C}{l} - 3$$$ operations. The number of operations is minimised when $$$l$$$ is maximum, so $$$l := \gcd(A, B, C)$$$; to solve the problem just check if the minimum is at most 3. 228383697

(I saw a lot of people at the top of unofficial standings iterating over $$$(A + B + C) / l$$$ and testing each of them using this condition; it's quite strange to me that they didn't use GCD instead...)

G: There is no need for Fenwick trees or segment trees, you can check palindromes using just the difference array (and maintain bad positions using std::set as in the tutorial). 228383431

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

Can someone Please help me with the problem F . My code 228434471 is giving wrong answer at Test 4.

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

Problem G with sets and vectors is also possible submission

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

Can anybody can tell me whether my solution in F can use when it have the edge-weight?Can it be called DP?228766385

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

Is it possible to solve F with centroid decomposition? I had TLe attempts

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

Can someone explain what does this mean ~ Notice that palindromes do not appear or disappear inside a segment, but they can appear or disappear at its boundaries

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

G can also be solved only with segment tree. In each node we keep track of the first two characters in the interval as well as the last two (or just one character if its a leaf). Then when we merge two intervals we just keep check if a palindrome is formed at the edges. Updates can also be handled very simply by just applying the shift operation to the characters we keep track of. AC with this idea: https://mirror.codeforces.com/contest/1881/submission/240931303

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

can you explain to me why in E we are updating dp[i] as

dp[i]=min(dp[i+1]+1,dp[i+a[i]+1]) and not as

dp[i]=min(dp[i+1]+1,dp[i+a[i]+1+j]+j) for all j st i+a[i]+1+j<n indexing from 0

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

can some body explain d part

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

editorial not loading for F problem

showing "Unable to parse markup [type=CF_MATHJAX]"