### cyand1317's blog

By cyand1317, history, 10 months ago, ,

Greetings!

Codeforces Round #418 (Div. 2) has just come to an end. This is my first round here, and hope you all enjoyed the contest! > <

Seems the statements still created a few issues :( Anyway hope you liked it, and the characters feature the Monogatari anime series. Let me state again that the statements has little to do with the actual plot — they're inspired by five theme songs actually — and I'm not spoiling anyone of the series! ^ ^

Sympathy for those failing system tests on B... This problem was intended to experience a lot of hacks but somehow there are not so many.

Here are the detailed solutions to the problems. Feel free to write in the comments if there's anything incorrect or unclear.

Tutorial is loading...
Solution 1
Solution 2
Tutorial is loading...
Solution 1
Solution 2 - Casework
Tutorial is loading...
Solution
Tutorial is loading...
Solution 1 - DP on trees
Solution 2 - Greedy

One more thing — Staying up late is bad for health.

Tutorial is loading...
Solution 1 - O(n^5)
Solution 2 - O(n^3) by KAN

This is the round with the most solutions so far perhaps? There are at least 3 × 2 × 3 × 3 × 3 = 162 different ways to pass all problems in this round =D

Pla-tinum happy though I'm supposed to be
Pla-tinum sad is somehow how I get

Personally I'd like to express my gratitude to the community for creating this amazing first-time experience for me. Thank you, and see you next round. Probably it will be for Ha... Well, let's wait and see :)

Cheers \(^ ^)/

•
• +222
•

 » 10 months ago, # |   0 Thanks for fast editorial :)Please fast rating update too :)
 » 10 months ago, # |   +2 Bonus. Figure out why solution 2 is not hackable. Because all permutations of b (maybe except sorted) is valid?
•  » » 10 months ago, # ^ |   +2 Seems legit. The loop will not be executed more than twice.
 » 10 months ago, # |   0 Auto comment: topic has been updated by cyand1317 (previous revision, new revision, compare).
 » 10 months ago, # |   0 Thank you for the great problems, especially problem C and D :)
•  » » 10 months ago, # ^ |   +30 You have got 803 rating in one contest! This is the biggest change I have ever seen. Translation: Is there any kind of operation like this? O(∩_∩)O
 » 10 months ago, # | ← Rev. 2 →   +20 Problem E is awesome. I had a O(n^6) solution at the beginning and made it O(n^5) soon. Then I spent nearly an hour to optimize it. Finally I got a O(n^4) solution and the contest ended.Anyway this problem is a really graceful dynamic programming problem in my opinion, which made me doubt whether I was solving problem in topcoder. Just an analogy, don't mind :)
•  » » 10 months ago, # ^ |   +15 Agree.I also had an O(n^6) solution at the beginning, made it O(n^5) soon, but when I was writing the code I found that there's a useless dimension in my DP status, deleting it resulted in an O(n^4) solution...
•  » » » 10 months ago, # ^ | ← Rev. 2 →   +13 What is the O(n^4) solution? I know an O(n^5) solution using DP state comprising of index, 2_left_in_last_level, 3_left_in_last_level, 2_left_in_current_level and 3_left_in_current_level.
•  » » » » 10 months ago, # ^ | ← Rev. 2 →   +13 It can be seen that you have to connect exactly one point left in the last level if there has one. So you just need to keep the number of points in the last level. When the current level becomes the last level, calculate the number of ways of these points connect to some points on the right (but we don't care about what these points are), which is actually equal to the number of permutation with repetition.
•  » » » » 10 months ago, # ^ |   +28 2_left_in_last_level and 3_left_in_last_level can be merged: remain_degrees_in_last_level = (2_left_in_last_level + 2 * 3_left_in_last_level).In the O(n^5) solution, we multiply the answer by (2_left_in_last_level) and then decrease (2_left_in_last_level) by 1 if we choose a vertex with 1 remaining degree in last level, or multiply the answer by (3_left_in_last_level) and then decrease (3_left_in_last_level) by 1 and increase (2_left_in_last_level) by 1 if we choose a vertex with 2 remaining degrees in last level.In fact we can precalculate the number to be multiplied when we change the level: (remain_degrees_in_last_level)! / 2^(3_left_in_last_level). (can be proved with combination knowledge)In the O(n^4) solution, we just merge 2_left_in_last_level and 3_left_in_last_level into remain_degrees_in_last_level, and multiply the answer by (remain_degrees_in_last_level)! / 2^(3_left_in_last_level) when we change the level, no longer caring whether to choose a vertex with 1 or 2 remaining degree(s) in last level.
•  » » » 10 months ago, # ^ |   +8 You did a good job :)
•  » » 10 months ago, # ^ |   +18 Thanks for your appreciation! What a pity you didn't make it >
•  » » » 10 months ago, # ^ |   0 But I think memory limit is too tight for n^5 solution.I got dp[2][2*N][2*N][N][N] and passed with 247MB.
•  » » » » 10 months ago, # ^ |   0 Yes, perhaps the ML should have been larger in order to let all O(n5) solutions pass easily. But you can try some different DP that would use an f[2][N][N][N][N] array.
•  » » 10 months ago, # ^ |   0 Can you explain what topcoder problems are like? I never understood topcoder I created an account but the interface was too crowded and complicated. What do you mean by "which made me doubt whether I was solving a problem in topcoder"?
•  » » 10 months ago, # ^ |   +25 If it's Topcoder, you won't come up with a polynomial-time algorithm at the beginning. lol
•  » » 10 months ago, # ^ |   0 Can you tell me how I can improve my dynamic programming skills ? I had no idea how to approach that problem at all. Thanks.
•  » » » 10 months ago, # ^ |   +21 Practice and struggle. That's all there is to life, my friend. :)
•  » » » » 10 months ago, # ^ |   0 I meant some resources with easy DP problems and then building up ...
•  » » » » » 10 months ago, # ^ |   +5 You're literally sitting on the best website for resources.Here you go. Solve some problems, and when you start finding them easy, then skip a few. Repeat.
 » 10 months ago, # |   0 why is my solution got TLE ? cyand131727649598same complexity passed with many others
•  » » 10 months ago, # ^ |   +12 Your solution has a factor if I got it right, and that actually is not intended. Similar solutions will get AC or TLE depending on implementation, so next time remember to test it against maximum data :)
•  » » » 10 months ago, # ^ |   0 You should have let all the O(n*q) solutions pass :P
•  » » » 10 months ago, # ^ | ← Rev. 2 →   +5 Woow the big array size was the cause of TLEsame code .. good array size passed O.ocyand131727656648aka.Sohieb
•  » » » » 10 months ago, # ^ |   0 But I am still interested in why it says your code got TLE not MLE?
 » 10 months ago, # |   0 anyone who completed problem c in java ?
•  » » 10 months ago, # ^ |   0 with python3 i can not make less than 5.5s :(
•  » » 10 months ago, # ^ |   +1 Yeah you can do some precomputation and solve all cases before you take in queries (there are only n*26 different cases) and then just print out the queries as you get them. Ran in less than 500ms.
 » 10 months ago, # |   0 Can anyone please explain the solution for Problem — C.I am not able to understand the editorial.
•  » » 10 months ago, # ^ |   0 Which particular part of it? Perhaps I can make it clearer.
•  » » » 10 months ago, # ^ |   0 The Preprocessing Part.What do you do for each letter?
•  » » » » 10 months ago, # ^ |   +1 Mm, I'm rewriting the tutorial and it will be updated soon.
•  » » » » » 10 months ago, # ^ |   0 Thank You for your effort!!!
•  » » 10 months ago, # ^ | ← Rev. 2 →   +3 Clearly, given a color c and a number of repaints m you could bash through all possible intervals and find the maximum valid substring, but this would take too long, with n(n+1)/2 possible intervals and q queries, taking O(n^2*q) time.We can resolve this issue as there are 26n possible queries (as there are 26 letters in the alphabet and m is constrained to [1,n]. Therefore we run through every possible query and store its answer in an array Ans[c][m]. (this takes O(n^2*26) time)To run through every possible query we look at every possible color and every single possible subinterval, and find the minimum number of recolors needed to make that interval valid. We compare the size of this interval to the size currently stored in Ans[c][r-l+1-t], and store the maximum of the two.However, this only finds the maximum value when exactly m colors are recolored, but in some cases not all m colors need to be recolored, for example take string axaxa for favorite color a, a maximum of 2 recolors will be needed even if we have more than 2 recolors available. Therefore, for each color we iterate through [1,m] and if Ans[c][j] is less than Ans[c][j-1], we replace Ans[c][j] with Ans[c][j-1]. Using the above example, Ans[a][2] would = 5 while Ans[a][3] would = 0, and so we set Ans[a][3] to 5. (Restating what I said above: the maximum vaild substring given a number of recolors m is equal to the maximum valid substring that can be obtained by any number p such that 1<=p<=m. We originally only found answers which used exactly m recolors.)Then we handle each query by using this 2-D array as the solutions are precomputed.
•  » » » 10 months ago, # ^ |   0 Great!Thank You for your explanation!
•  » » » 10 months ago, # ^ |   0 = = really nice explanation!
 » 10 months ago, # | ← Rev. 2 →   0 Problem C. Got TLE with O(nq) solution. Any idea how to fix it? http://codeforces.com/contest/814/submission/27651582
•  » » 10 months ago, # ^ |   +1 Try adding the following code lines: int main( ) { ios_base::sync_with_stdio( 0 ); cin.tie( 0 ); // Your code here } I think that you got TLE because the input file is too large and cin/cout is a little bit slow without the lines above.
•  » » » 10 months ago, # ^ |   0 exactly
 » 10 months ago, # |   +4 Bonus for C in O(nq) can be easily done using two pointers (sliding window). SpoilerMaintain a left pointer l, and a right pointer r. For current window size, let cnt be the number of characters present in the window, that are not equal to c, which is the current favourite character. Now, while cnt <= m, we can expand the window, hence we increment r, and update cnt according to the new character added to the window. Once cnt > m, we increment l (and update cnt according to the character being removed from the window), and continue the process. At each valid window, we can check it's size, and update our final answer accordinglyCheck my submission for better understanding. Code
•  » » 10 months ago, # ^ |   0 I have the same solution and interesting in if there is a guarantee about working less than 2 seconds ? I was hoping only on power of computers of the verification system. As I know, approximate number of actions per second about 100 millions. So, we have O(n * q) ~ 300 millions actions and only 2 seconds.
•  » » » 10 months ago, # ^ |   +7 Though the solution with complexity O(n * q) passes, you can still optimize that solution. As m <  = 1500, the total number of unique queries can be 26 * 1500(as there can be 26 different alphabets for each m). Hence the queries in the input will repeat. So you can save the answers for the queries as you encounter them, and if that query is repeated again, you can simply print it directly without solving again. You can do this by maintaining an array dp[27][1510]. Here are my submissions with and without this optimization. Submission 1: 27657218Submission 2: 27657190There is a huge difference in time.
•  » » » » 10 months ago, # ^ |   0 I think it's similar to O(n^2 * 26 + q) as I understand, but I'm interesting in if there are some guaratees without optomization.
•  » » 10 months ago, # ^ |   0 I did C using Binary Search on the answer and checking whether for the particular value of answer is it possible to paint a subsegment by combining it with the sliding window. Code
•  » » 10 months ago, # ^ |   0 Smart solution :)
 » 10 months ago, # | ← Rev. 2 →   -8 Sorry found a bug in my code.
 » 10 months ago, # |   0 Can't understand the description of E. Must the graph be a tree?
•  » » 10 months ago, # ^ |   +5 No, the second sample itself is not a tree. But if you construct the shortest path graph, that will be a tree because there is a unique shortest-path from every vertex to the capital. Apart from these edges of the tree, edges can be present between siblings nodes in the tree.
•  » » » 10 months ago, # ^ |   0 can u pls explain a bit more what the states represent here. thx
 » 10 months ago, # |   +5 Could someone explain me a solution of problem D, please.
•  » » 10 months ago, # ^ | ← Rev. 2 →   0 I solved D with Dynamic programming(memoization): D[1111][2][2][2]: D[node][|set1|_is_odd?][|set2|_is_odd?][node_belogs_to_set2?]Then the core part becomesD[node][odd1][odd2][at_odd2] = (odd1 && !at_odd2) || (odd2 && at_odd2) ? area[node]: -area[node] + get_optimal_combination(direct_children[node])Here, direct_children consists of literally indices of direct children, which means, for each y in direct_children[node], there is no other circle smaller than node which is parent of y.And get_optimal_combination is simple, too: this is just a sum of max(D[child][!odd1][odd2][false], D[child][odd1][!odd2][true]); (this is obvious so that I will omit the proof).P.S. I think this problem can solved using plain DFS without DP.
•  » » 10 months ago, # ^ |   0 If we define the level of a circle as the number of circles that completely enclose it, then for any circle, its effective area can be seen as sum of all the even levels minus the sum of all the odd levels. My solution was to move to the second plane all circles whose level is 1, that is, all the circles that have exactly one circle enclosing them. It's pretty easy to see why this works, but let me know if you need a proof. 27655767
•  » » » 10 months ago, # ^ |   0 Could you please give a proof? Thanks a lot.
 » 10 months ago, # | ← Rev. 2 →   0 In test case 6 of problem B:  10 1 2 3 4 5 6 7 8 4 10 1 2 3 4 5 6 7 6 9 10 my output is : 1 2 3 4 5 6 7 6 4 10 Jury's answer was : 1 2 3 4 5 6 7 8 9 10 But the problem says,it satisfies any permutations maintaing (n-1) matches..I can't find any errors with my output.It would be very helpful if someone helps me with my confusion.Thanks in advance.
•  » » 10 months ago, # ^ |   0 @TajirHas9 the answer should be a permutation of 1,2,3....n .Read the problem statement again!
•  » » » 10 months ago, # ^ |   0 Thank you very much.I noticed that now.I thought any permutation is acceptable.But problem statement says 1 to n inclusive indeed. :(
 » 10 months ago, # |   0 I can't understand how spaciousness is defined in problem D?Is it unique for given set of circles.How are those odd ranges chosen?P
•  » » 10 months ago, # ^ |   +1 The spaciousness is the total area that is covered by an odd number of dancers. So, for example, if a region is covered by only one dancer, this region is included in the computation of total spaciousness, if a region is covered by exactly two dancers, it is not.Your goal in the problem is to maximize the total spaciousness by allocating some dancers to dance only after midnight and some to dance only before midnight.
 » 10 months ago, # | ← Rev. 3 →   0 c problem .....in the editorial code->what is the use of this loop:- for (int i = 1; i < MAXN; ++i) ans[c][i] = std::max(ans[c][i], ans[c][i — 1]); 
•  » » 10 months ago, # ^ |   0 isn't for (int i = 1; i < MAXN; ++i) ans[c][i] = std::max(ans[c][i], ans[c][i - 1]);
•  » » 10 months ago, # ^ | ← Rev. 5 →   0 The mean of ans[c][i] : the best ans when exactly change i times.You can not change so many times with string : aaaaaaaaa and query 4 aSo that you should get a prefix max。
 » 10 months ago, # |   0 I don't understand what is this "26" in the editorial of problem C
•  » » 10 months ago, # ^ |   0 You have to precompute for each possible color, and there are 26 alphabets so 26 possible colors.
 » 10 months ago, # |   0 Auto comment: topic has been updated by cyand1317 (previous revision, new revision, compare).
 » 10 months ago, # |   0 I am getting RTE in my code for strings of length > = 30 . I am unable to understand why this is happening as the number of alphabets are only going to be 26 . As soon as I replaced 30 with N , I got an AC . Pleas help me out . Thanks in advance.AC solution : here RTE solution : here
 » 10 months ago, # |   +3 Can anybody explain how the tree structure in problem D can be built in O(n log n) ?
•  » » 10 months ago, # ^ | ← Rev. 2 →   +33 Using BST and scanning line.First we divide each circle into two arcs,the upper one and the lower one.Then process all arcs from left to right,inserting and deleting arcs in the BST.In the BST we sort the arc by vertical order.(As no circles intersect,each pair of arcs can be compared vertically).When we insert an upper arc,we can find the closest arc which is on top of it. If the closest arc which is on top of it is an upper arc,then the closest arc is the parent of the arc being inserted.Otherwise,we find a lower arc or no arc at all.If no arc at all,the arc being inserted can't be contained by any other circle.If a lower arc is found,this lower arc should have the same parent as the arc being inserted.There're some computational geomatry problems employing this technique in Chinese OI.Poor English,a better explanation is needed.
•  » » » 10 months ago, # ^ | ← Rev. 2 →   -11 Notice that we have n ≤ 1000, so using O(n2) brute force is already enough.
•  » » » » 10 months ago, # ^ |   +18 Oops, didn't notice that we're talking about the solution. I won't be so careless again.
•  » » » 10 months ago, # ^ |   0 Thank you for your explanation.
•  » » » 10 months ago, # ^ |   0 would u like to explain how to deal with two circles are tangent with each other?
•  » » » » 10 months ago, # ^ |   0 I'm struggling to get your solution correct...After replacing the DP part with my AC code and some changes to the cmp() function it now get WrongAnswer on test 27 http://codeforces.com/contest/814/submission/27671766Still trying now.
•  » » » » » 10 months ago, # ^ | ← Rev. 2 →   0 ah i am really appreciate that, i realize the reason i got wrong answer may because of my original wrong dp... >>i think that, coz i build a virtual node, so maybe u have to count in another way, like ans += f[0][0][son] if(x is n+1)anyway, cheers
•  » » » » » » 10 months ago, # ^ |   0 http://codeforces.com/contest/814/submission/27672108 Accepted now. Some changes to "operator <" were added in this version.When compare arcs,we use "upper" "lower" in the straightforward meaning:whether they seems upper/lower
•  » » » » » » » 10 months ago, # ^ |   0 wow nice one :)danks!
 » 10 months ago, # |   0 Auto comment: topic has been updated by cyand1317 (previous revision, new revision, compare).
•  » » 10 months ago, # ^ |   0 Is problem C a form of a classic DP problem??
 » 10 months ago, # |   0 Ah ha~~~ What do you mean by using 'Let's wait and see." ~~~ ^_^
 » 10 months ago, # |   0 Is problem C a form of a classic DP problem??
•  » » 10 months ago, # ^ |   +5 I think it's quite classic. It's not DP but preprocessing + sliding-window method actually, though the memorizations are a bit alike.
•  » » » 10 months ago, # ^ |   0 can you tell me the name of the classical problem which is similar to that problem??
•  » » » » 10 months ago, # ^ |   0 I mean, this technique is similar to DP, though it isn't. There are quite a few DP problems on strings out there but I can't think of one right now. Perhaps someone else might help.
•  » » » » 10 months ago, # ^ | ← Rev. 2 →   0 I think the most classical idea in this problem is "noticing" you are dealing with an alphabet with 26 letters, so you can preprocess individually. Exploring this idea is useful for a handful of problems that have different approaches. Even tries would not have the same complexity if your alphabet was greater. You could find a longest non decreasing subsequence of characters in O(26*n), as another example.
 » 10 months ago, # |   0 I couldn't understand DP on trees for problem D.Can someone explain a bit more on that DP part?Thanks in advance and sorry if the question seemed to be trivial.
 » 10 months ago, # |   0 how could u construct the tree for D in ?particularly plz specific how to deal with two circles tangent with each other.coz i used sweepline + set which leads to Wrong answer on 4 >.<
•  » » 10 months ago, # ^ |   0 I the same WA on testcase 6
•  » » » 10 months ago, # ^ | ← Rev. 5 →   0 wa on case 6 may be the wrong idea with dp >>what i did is for each i's sonbut it is wrong, we should count his brothers inwhich should be and then hmm, exactly the same as the solution.
•  » » » » 10 months ago, # ^ | ← Rev. 2 →   0 Thank U all the same though I use greedy algorithm... I was considering that methods discussed above by liu_runda is too complicated Maybe we could only deal with upper arcs (Keep trying...
•  » » » » » 10 months ago, # ^ |   0 ah okay, for that one, u can draw two graphs, if the one with shorter distance to it is upper arcs, the current circle we are looking at, is contained by the circle which the particular upper arcs belongs to.On the other hand, if it is a lower arcs, they must have the same situation, which means they are brothers.
 » 10 months ago, # |   0 I don't understand the formular f[u][0/1][0/1] of D's solution. What does it mean?
•  » » 10 months ago, # ^ | ← Rev. 2 →   +6 Let F[u][isOddGroup1][isOddGroup2] be the best sum for distributing the circles between first group and second group optimally, so you can either make the circle u in the first group or the second group, and either sum or subtract the circle u area according to the parameters isOddGroup1 and isOddGroup2 respectively.
•  » » » 10 months ago, # ^ |   0 so the result of the tree root u should be max(f[u][0/1][0/1])?
•  » » 10 months ago, # ^ | ← Rev. 3 →   +3 f[u][p1][p2] is the maximum total answer in the subtree of u, assuming there are p1 nodes assigned to the first group and p2 nodes assigned to the second group among u's ancestors. And we only need to care about the oddness/evenness of p1 and p2 so we store them modulo 2.Edit: Seems I was a bit too slow XD
•  » » » 10 months ago, # ^ |   0 For a node u, we look at its ancestor, that's clear. What's not clear is why we use u's subtree to calculate f instead of its ancestors. The provided solution does exactly that, doesn't it?
•  » » » » 10 months ago, # ^ |   +1 In the editorial, p1 and p2 are kind of assumed. So f means "what's the best we can get in the subtree, if the ancestors are in this state." We calculate this value bottom-up, and u's value will be used by its parent.Other approaches may not use ideas like this, though.
 » 10 months ago, # |   0 Can any one guide me how to do Problem c with top down dp approach.I have written the recursive implementation but i am unable to memoize ,that's why i am getting tle.Thanks in Advance.Here is my solution link
•  » » 10 months ago, # ^ |   0 Here is my top down code. I think it is self explanatory.
 » 10 months ago, # | ← Rev. 4 →   0 In problem E, why can't we club p1 and p2, and club c1 and c2, and have dp[u][p1 + 2*p2][c1 + 2*c2], which denotes number of ways to build the graph with the first u vertices, with (p1 + 2*p2) plugs in the previous level, and (c1 + 2*c2) in the current one?
•  » » 10 months ago, # ^ |   +3 Because then you could pair two nodes twice, which is not permitted.
 » 10 months ago, # |   0 why title of C and E is not English?
 » 10 months ago, # |   0 Hello,what do we mean by Figure out why solution 2 is not hackable. what is the meaning of hackable and why is not hackable. is the solution 1 hackable?
•  » » 10 months ago, # ^ |   +16 Solution 2 seems to have a complexity of O(k!*n). (though it's O(n+k) indeed)Both solution 1 and 2 are correct (not hackable).
•  » » » 10 months ago, # ^ |   0 Can you please explain the general idea of the second solution?
•  » » » » 10 months ago, # ^ |   0 This problem asks us to "detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing".The second solution is just a simple idea: to try every way to "replace each zero in a with an integer from b so that each integer from b is used exactly once", and then check if "the resulting sequence is not increasing".As this comment said, "all permutations of b (maybe except sorted) is valid". So the O(k!) loop will break; in O(1).
 » 10 months ago, # |   +1 In problem D I can't understand this statement " consider a vertex u, and the parity (oddness/evenness) of number of nodes in its ancestors from the first and the second group."in this matrix f[u][0/1][0/1] what represent the second and the third dimension I didn't get itthank you in advance
 » 10 months ago, # | ← Rev. 4 →   0 You can solve D with pure DFS, no DP needed.for every tree, Add the root to the first group, and the the children of the root to the second group , so answer = Area of Root + Area of each of the root's children, after that either add the area of the current circle to the total answer if the depth is even , or subtract the area if the depth is odd.This works because, if The maximum depth of the tree is 2, it is optimal to put the root on one side and the root's children on the other side,then you simply add all the areas to the final answer,but if you add another smaller circle into the plane, you increase the depth by one so this new circle area will definitely get subtracted if put on any side,we solve this by adding its children(which have depth4) inside it(to decrease the loss of area),then same goes for circle of depth 5 and its children.http://codeforces.com/contest/814/submission/27689113
•  » » 10 months ago, # ^ |   +5 Is the explication given by Karemm_Mohamed false??why many people dislike his answer?
 » 10 months ago, # | ← Rev. 3 →   0 Can you explain for me how to dp array WAYS of solution n ^ 3 in problems E.I don't understand how it work and remarks in code such as // 2-0, 2-0 // 2-2, 2-0 .... etc !
•  » » 10 months ago, # ^ |   +8 Just a rough idea for understanding the sample solution: consider what happens when we add edges among vertices of the same level (with c1 "1-plug" vertices and c2 "2-plug" ones), and from a vertex in that level to a vertex in a new level (with c0 vertices). "Plugs" of certain vertices will decrease (some "2-plug" vertices become "1-plug" for example), depending on the edges we choose.We take a vertex and consider how they're connected to other vertices. The comments are in the form of "(the vertex we're currently considering) — (the vertex it's connected to)". e.g. "2-1, 2-0" means we take a "2-plug" vertex and connect it to a "1-plug" vertex in its own level and a vertex in the new level (denoted by 0). We can choose different vertices of the same "plugs" to connect to, so previous DP values are multiplied by number of such ways, like .
•  » » » 10 months ago, # ^ |   0 Thanks for your help. I understood !
 » 10 months ago, # |   +1 Can someone explain their greedy solutions for D with proof of correctness ?
•  » » 10 months ago, # ^ |   +3 The comment above by Kareem_Mohamed is a common one FYI (basically it's explaining exactly Solution 2 in the tutorial, I don't know why it's downvoted :/). I've seen a few approaches equivalent to this, but I'm also curious whether someone came up with other insights and ended up in the same solution.
 » 10 months ago, # |   0 Above all thanks for the great DP round. XDHere is one question. For problem E's sample O(n3) solution, there is a part of constructing from subproblem which says "if (c2 > 2) add(ways[c0][c1][c2], (ll)ways[c0][c1 + 2][c2 — 3] * ((c2 — 1) * (c2 — 2) / 2)); // 2-2, 2-2"As c1, c2, c0 are all limited under 50. How can we guarantee we always have future information [c1 + 2] when we need to calculate f[c0][c1][c2]? For example, when calculating f[1][49][30], we don't have the memo of f[1][51][27] cause c1 is larger than 50.
•  » » 10 months ago, # ^ |   0 For indices larger than 50 the corresponding DP values are all 0 due to implicit array initialization. And note that DP values are calculated in c0-c2-c1 order so we can be sure the values we need at some time are all calculated before.
•  » » » 10 months ago, # ^ |   0 Well, I got this one, thank you! Would you pls give me a hint on how to set the initial value for ans[n][n — 1] = 1. Is there any physical meaning for this?
•  » » » » 10 months ago, # ^ |   0 There is one way to build a graph with vertices numbered between n and n - 1 — "no vertices", and "no vertices" form the first level, that is, zero edges from the previous level need to be connected to it.
•  » » » » » 10 months ago, # ^ |   0 That is clear, thanks a lot!
 » 10 months ago, # |   0 Why in Problem D are we considering the parity part in our dp states..I did'nt get it..though it is giving the correct answer.What should prompt me to think about the parity of the ancestors?
•  » » 10 months ago, # ^ | ← Rev. 2 →   0 Will this make it clearer?: The subproblem is that what is the biggest spaciousness that all nodes in u's original subtree can achieve. As u can choose to join group 1 or group 2, there are at most 4 states. Note that when considering f[u][..][..], we are considering all nodes in u's original subtree, but they may not be in u's subtree in a specific group.
 » 10 months ago, # | ← Rev. 2 →   0 cyand1317 could you explain the dp states in D?For a node u, does f[u][0][0] mean that u belongs to the first group and has depth%2 = 0?
•  » » 10 months ago, # ^ |   0 This comment FYI :)
 » 10 months ago, # | ← Rev. 2 →   0 I got an easy greedy solution for Problem D. Pretty straight forward 20 (actual) lines of code.SubmissionBasically take circles in decreasing order of radius. Find its immediate encompassing-circle. Then depending on the "tag" of that parent-circle, assign the "tag" for the current circle. Then add certain values of "tags".Essentially I skipped the trees. And Dfs.
 » 10 months ago, # |   0 I'm having trouble understanding the problem D and it's example test cases. what does the area covered by an odd number of movement ranges of dancers who are moving. actually mean? how exactly is spaciousness calculated??
 » 10 months ago, # |   0 How would you do the bonus for problem D?