Educational Codeforces Round 164 Editorial
source link: https://codeforces.com/blog/entry/128421
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
why unrated? UPD:I understand |
7 days ago, # | why unrated? |
-
if you read the blog for latest div 2 contest it states that "UPD: The rating changes for Educational Codeforces Round 164 will be applied after this round."
7 days ago, # | Alternative solution for E: transpose the array (find indices of each value), then iterate from amaxamax to 11 and count islands[k]islands[k] — the number of groups of connected monsters after doing kk dmg. Then just sieve ans[k]=∑i=1,2,3,..,⌈amaxk⌉islands[i⋅k]ans[k]=∑i=1,2,3,..,⌈amaxk⌉islands[i⋅k]. 256372546 |
7 days ago, # | is the contest unrated |
7 days ago, # | Correct me if I'm wrong, Educational contest will not effect the rating, right? |
Talking about the complexity of E — do we need to multiply it by 1+1/2+...+1/A? Or should we count it as a constant? |
7 days ago, # | F has almost linear (O(n*log log n)) solution: The high-level idea is the same, but I managed to calculate FixedPoints(g) in O(g). Since sum of divisors grows as O(n*log log n), the overall time complexity is the same. |
7 days ago, # | Problem D, are there any similar problems with the idea of the 'standard problem' said in the solution? |
-
Check this one out. It is based on that standard problem. FYI, editorial for this does a good job of explaining it. If you still have confusions on how it works think Bipartite Graphs.
-
Thank you!
-
For those interested in a formal proof, I think this might help: https://en.wikipedia.org/wiki/Tutte_theorem
The problem of maximizing the number of pairs can be reformulated as determining whether graph has a perfect matching (or near perfect matching if |V| is odd).
As for the theorem, the only way to create >1 connected components is to remove all colors except one (i). Theorem says that a[i] <= number of removed vertices, which is sum(a[j]) for all j except i.
Hope this helps anyone :)
-
-
6 days ago, # | problem E Whats the coefficient thing? I understand that we need to have some coeff for all ai so that its easier to sum over, and then formula is given to find coeff, whats the intuitive rational on what are we trying to achieve? |
-
The coefficient comes from expanding the equation. We can see when max(0, a[i] — a[i — 1]) contributes to the sum.
For this a[i-1] should be less than a[i]. Then if a[i-1] < a[i], a[i] adds to the formula ( (+1) * a[i], where +1 is the coefficient). Now notice that a[i] also appears in the next consecutive difference, namely a[i+1]-a[i]. So if a[i] < a[i+1], as you see we should subtract a[i]. Thus ( (-1) * a[i] ) should be added. So for example, coefficient is (+1) + (-1) = 0 when both if's hold
6 days ago, # | For problem D, O(N * V) solution works. Actually when upsolving I didn’t notice the restriction on the sum of a[i] but still solved with all core ideas which are in the official solution. The idea is that for an element to be > (sum of other elements), sum of elements is bounded by 2V. |
6 days ago, # | In problem D, during the contest, I did not notice a limit on the sum of all the elements of the array. However, even without this limitation, the problem can be solved in O(N* maxA). In my solution, I keep a knapsack for sums less than 5000, and separately store the number of possible even/odd sums, as well as the sum of all possible even/odd sums of subsets. There is my code for this task: 256335037 |
6 days ago, # | Hey guys, can you suggest some problems similar to "D" in here. I am seeing too many different implementations of the same exact ideas with massive variations in runtime & memory. I implemented the same idea with a take / not-take dp where I consider both possibilities of taking/not-taking current element in a set : 256634006. I want to make sure if this method is enough for such problems or should I consider other implementation too. Hence, if you know any similar problems, please reply. |
-
Can you tell why sorting the array of colors is required?
-
To calculate the minimum number of groups formed in a set, it is either the biggest element or ceil(half of total sum). Now why is that? Its because if the biggest element is bigger than or equal to the sum of the rest of the elements, you can completely pair up every other element with it, if it is less than the sum of rest of the elements in that set, then you will do random pairing which will result in ceil(sum/2) teams.
To avoid calculating the biggest element, I have sorted it. So that the last element in a set is automatically the biggest element in it.
Refer to dry running sample case 3 for complete understanding.
-
-
I created a video talking about the optimal placement for the balls in D: Colored Balls.
-
-
Sure, you can take a look at my submission where I do the same thing, but with explicit DP arrays.
For a prerequisite, watch this video timestamp 10:50 to 14:30
As stated in the video, in iterative DP problems, you should always think about how you can "refresh" the answer when you append an element to the already constructed answer.
Suppose you are processing elements in increasing order, and you've already created all the subsets possible so far, denoted by
dp[sum]
. Now, what happens when you append a new element? There will be 2 new class of subsets : Those which are already created, and those where you compulsorily add the current element in all of the already created subsets.Sondp[sum] = dp[sum] + dp[sum - a[i]]
But if you keep on constructing the subsets and wait to compute the answers at the end, it'll be too late, because by that time, you might not know that maximum element of the subset. So, we'll impose a rule : Construct the answer for all the subsets necessarily containing a[i]a[i] when you see a[i]a[i] for the first time.
So, in order to avoid mixing the subsets, we will first compute the answer when we add a[i]a[i]. Let's create a temporary DP ndpndp, which will contain all possible subsets that have a[i]a[i]. It's clear that
ndp[sum] = dp[sum - a[i]]
Note that we intentionally removed the addition since we don't want to pollute our subsets. Now, what is special about the subsets represented by ndpndp? All these subsets would have max element as a[i]a[i]. Therefore, we can compute the answer as max(sum/2,a[i])∗ndp[sum])max(sum/2,a[i])∗ndp[sum])
Once we've computed the sum, we can finally mix these subsets, because we no longer need to track the max info anymore. Therfore,
ndp[sum] += dp[sum]
-
-
This approach & one mentioned in tutorial seem to faulter in case of suppose input is 3 balls with count 7 7 7 respectively, the approach mentioned gives 53 as output but manually checking it gives 56 as output.
Is input I mentioned valid, if valid then kindly someone guide why is this happening. tutorial approach:
singleton sets {7}*3 value=7*3
sets with two elements {7,7}*3 value=7*3
sets with three elements {7,7,7} value=11 because no element is greater than half of sum of balls (21+1)/2, but actually value should be 14 as two colored balls 7 each will be paired together & form 7 groups and 3rd colored ball will also form 7 groups so total is 14 not 11.
BledDest pls guide.
-
6 days ago, # | There's a typo in editorial for F. Formula for allall should be ∑oni=0(gi)∑i=0on(gi) instead of ∑oni=0(gon)∑i=0on(gon). |
Can author explain me why "It means that if gcd(i,n)=gcd(j,n) then FixedPoints(i)=FixedPoints(j) since in both cases we'll get exactly the same group division. So, we can rewrite the answer as following" true ? while FixedPoint(i) depend on "no more than c+k ones and at least c consecutive ones" and group of 2 case different. Thank. |
6 days ago, # | Thank you for fast editorial |
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK