By Vladosiya, history, 13 months ago, translation, 1675A - Food for Animals

Idea: MikeMirzayanov

Tutorial
Solution

1675B - Make It Increasing

Idea: MikeMirzayanov

Tutorial
Solution

Idea: Gol_D

Tutorial
Solution

1675D - Vertical Paths

Idea: MikeMirzayanov

Tutorial
Solution

1675E - Replace With the Previous, Minimize

Idea: myav

Tutorial
Solution

Tutorial
Solution

1675G - Sorting Pancakes

Tutorial
Solution Tutorial of Codeforces Round 787 (Div. 3) Comments (25)
| Write comment?
 » With respect to the F problem, another (maybe simpler?) explanation: hang the tree from x (or y, it's equivalent) iteratively remove all leaves that are not in a or [x, y], we'll end up with only nodes that we'll visit all edges from the resulting graph need to be traversed twice (back and forth), except the ones connecting x to y if the graph after step 2 has n edges, the solution is 2 * (n — 1) — depth[y]
•  » » » It is exactly that, after removing from the graph all the leaves that aren't in a. You can have a look at my submission: https://codeforces.com/contest/1675/submission/156053555
 » 13 months ago, # | ← Rev. 2 →   In case someone is interested, I made video Solutions for D-F
•  » » Video Solution for G
•  » » » sharmaharisam epsilon_573 you guys should do a collab, since one has uploaded d, e, f and the other has uploaded g. (YouTube collab, not contest collab xD).
•  » » » » 13 months ago, # ^ | ← Rev. 2 →   Actually I was recording A-F last night, but E was so tricky to explain intuitively... I just skipped the video altogether :p
 » 13 months ago, # | ← Rev. 2 →   .
 » Maybe C is simpler if we do3 Cases: It is a '?' increment counter it is a 0, return counter + 1 it is a 1, reset the counter and set it to 1.
•  » » why we set it to 1 when we get it is 1?
 » Can anyone explain what does int lend = min(j, k - a[i]); mean, in problem G?
•  » » 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]).
 » Question D，why I always got tle if i look for the path from up to bottom?
•  » » and also tle with the tutorial's method
 » My $O(n * m^3)$ for G almost got TLE. Submission
 » 13 months ago, # | ← Rev. 2 →   Any resources or similar problems to better understand G? Still confused by just reading editorial.
 » Can anyone explain the solution of the problem G-Sorting Pancakes??
•  » » 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].
•  » » » 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?
•  » » » » 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.
•  » » » » » thank you for ur fast response sir :D
 » Can someone explain the solution for problem E. Tutorial is somewhat complicated to understand.
 » 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?
•  » » Got it
 » 13 months ago, # | ← Rev. 2 →   I solved problem F with dfs, dp, and LCA+binary lifting. A lot more stuff than needed lol156882408 Warning: Code is quite messy and I haven't commented. Enter at your own peril.