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

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

1675A - Еда для животных

Идея: MikeMirzayanov

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

1675B - Сделай возрастающую

Идея: MikeMirzayanov

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

1675C - Детективная задача

Идея: Gol_D

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

1675D - Вертикальные пути

Идея: MikeMirzayanov

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

1675E - Замени на предыдущий, минимизируй

Идея: myav

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

1675F - Влад и отложенные дела

Идея: Vladosiya

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

1675G - Сортировка блинчиков

Идея: Vladosiya

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

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

With respect to the F problem, another (maybe simpler?) explanation:

  1. hang the tree from x (or y, it's equivalent)

  2. iteratively remove all leaves that are not in a or [x, y], we'll end up with only nodes that we'll visit

  3. all edges from the resulting graph need to be traversed twice (back and forth), except the ones connecting x to y

  4. if the graph after step 2 has n edges, the solution is 2 * (n — 1) — depth[y]

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

In case someone is interested, I made video Solutions for D-F

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

.

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

Maybe C is simpler if we do

3 Cases:

  1. It is a '?' increment counter

  2. it is a 0, return counter + 1

  3. it is a 1, reset the counter and set it to 1.

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

Can anyone explain what does int lend = min(j, k - a[i]); mean, in problem G?

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

    It's the number of pancakes, we need to take from dishes with bigger index. k — a[i] is how many is missing to get sum = k but we can't need more than j, because all pancakes on previous dishes are placed, so it's min(j, k — a[i]).

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

Question D,why I always got tle if i look for the path from up to bottom?

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

My $$$O(n * m^3)$$$ for G almost got TLE. Submission

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

Any resources or similar problems to better understand G?

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

Any resources or similar problems to better understand G? Still confused by just reading editorial.

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

Can anyone explain the solution of the problem G-Sorting Pancakes??

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

    In G, intuitively we see that a dp solution will work. If we want to put some pancakes on the ith dish, we need to have the same or more pancakes on the previous dish. To determine what can be put down later, we need to know how many pancakes we have put down previously. Hence, we need to take note of 1) how many pancakes we put down on the ith dish, and 2) how many pancakes we have put down in total. These will form our state. Hence we can have dp[i][number of pancakes on ith dish][number of pancakes put down in total] to describe our solution. The number of states for dp[n][m][m] is n * m * m which is 250 * 250 * 250 which is small enough.

    To transition to dp[i][j][k], we come from a previous state with fewer total pancakes. But the previous state's number of pancakes must be more. So we have dp[i-1][j2>=j][k-j] -> dp[i][j][k]. So, dp[i][j][k] = min(dp[i][j][k], dp[i-1][j2][k-j] + some transition value) for all j2>=j. The transition value (referred to as "add" in the editorial) is the number of moves required to go from a "pancake configuration" of having k-j pancakes in the first i-1 plates, to the same configuration but with exactly j pancakes on the ith plate. I don't know how people calculate these transition values elegantly. I had a greedy and incredibly messy way to calculate these.

    Finally, the answer is the minimum value for dp[n — 1][j][m], for 0<=j<=m. I hope this helps.

    You may refer to my solution 156195983 but it is in python, with the differences of me reversing a to solve for increasing pancakes, and I switched the definitions for j and k. So my definition is dp[i][prefix sum of pancakes up to i][number of pancakes on i].

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

      can u elaborate why the dp is : dp[i][number of pancakes on ith dish][number of pancakes put down in total] and why not dp[i][number of pancakes put down in total][number of pancakes on ith dish] ? Can we imagine this as a 3D matrix? If so, then what do the row, column and height of this matrix implicate?

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

        Both ways work. I used the latter which is dp[i][number of pancakes put down in total][number of pancakes on ith dish] in my actual solution. But the solution used in the editorial uses the former which is dp[i][number of pancakes on ith dish][number of pancakes put down in total].

        I will also discourage you from visualizing dp matrices spatially because it is very difficult and unnecessary. The important thing for doing dp is to have a firm understanding of the states, their transitions and their edge/boundary cases.

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

Can someone explain the solution for problem E. Tutorial is somewhat complicated to understand.

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

Can you please explain why in the task g dp transitions are d[i][last][k] = d[i-1][last][k-last] does it means that last = j, instead of last >= j?

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

I solved problem F with dfs, dp, and LCA+binary lifting. A lot more stuff than needed lol

156882408 Warning: Code is quite messy and I haven't commented. Enter at your own peril.