Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

### tourist's blog

By tourist, history, 7 years ago, translation,

Here is the tutorial of VK Cup 2017 Round 3 and Codeforces Round #412. Enjoy!

Is it rated?
T-Shirt Hunt
Success Rate
Dynamic Problem Scoring
Prairie Partition
Blog Post Rating
Test Data Generation
Tutorial of VK Cup 2017 - Round 3
• +570

| Write comment?
 » 7 years ago, # | ← Rev. 2 →   0 O(1) solution for DIV2C. Code
•  » » 7 years ago, # ^ |   +172 A bit simpler O(1) solution is described as the second solution in the tutorial.
•  » » » 7 years ago, # ^ |   0 I guess it is O(T) to be presize.)
 » 7 years ago, # |   0 I think I misunderstood DIV2 D. I thought Vasya could submit a wrong solution to a problem through the bots even if he has solved that problem correctly himself ? Is that wrong ?
•  » » 7 years ago, # ^ |   +95 That's correct, Vasya can submit wrong solutions to problems he has solved. In fact, though, submitting wrong solutions can be useful for just one thing — making a new account count as a round participant without solving any problems.
•  » » » 7 years ago, # ^ |   0 But wouldn't that help Vasya(in the case when he solves the problem before Petya) by lowering the solvers fraction and thereby increasing the maximum points he could gain from that problem ?
•  » » » » 7 years ago, # ^ |   +78 Well, yes, if Vasya solves the problem before Petya, he shouldn't submit correct solutions to it. He can submit either wrong solutions or just nothing.
 » 7 years ago, # | ← Rev. 2 →   0 How to solve Div2C this way? We have (x+c)/(y+c+d)=p/q; So (qx+qc) = py+pc+pd=> (qx-py)=p(c+d) — qc where (qx-py)= S. So we have linear Diophantine equation S=p(c+d) — qc with unknowns (c+d) and c. So is it possible to solve this problem this way and if yes, how would it be implemented?UPD: Sorry for duplicate
•  » » 7 years ago, # ^ |   0 I tried to do that. Here is my attempt 26939775It needs to be debugged a little, but general idea is correct. I've lost motivation to finish it once I knew that there is a much cleaner way :)
 » 7 years ago, # |   +15 for (int bots = 0; bots <= ((1 << k) — 1) * n; bots++) {In the code of 806B — Dynamic Problem Scoring, the '+' is gone as "&mdash"
•  » » 7 years ago, # ^ | ← Rev. 2 →   +15 Presumably it's a - (a dash), not a +.
•  » » 7 years ago, # ^ |   +54 Yes, it was meant to be a minus, not a plus :) Not sure why it transformed into "—". Fixed.
 » 7 years ago, # |   +6 Why the editorial is not appearing in contest page or announcement page? Please add link.
•  » » 7 years ago, # ^ |   +33 Thank you, added the link to the announcement page. It will appear on the contest page shortly.
 » 7 years ago, # |   0 In problem Div2 D the point calculation says -> 2000*(1 - 40 / 250) = 1680 Where 40 is the time of solve and 2000 is max point. So what happens if he solve a problem at 0 min from the start of contest? This case is valid as it is used in test case 3.Thanks in advance.
•  » » 7 years ago, # ^ |   +3 Naturally, he will get 2000·(1 - 0 / 250) = 2000 points.
•  » » » 7 years ago, # ^ |   +7 Sorry my bad.
 » 7 years ago, # |   0 For div2/C why do we have to put while(r-l>1)
•  » » 7 years ago, # ^ |   0 Binary search, google it.
•  » » » 7 years ago, # ^ |   0 Binary search says while(l while(r-l>0) not while(r-l>1)
•  » » 7 years ago, # ^ |   0 I wanted to ask the same question. Could anyone tell what's the difference between while (l < r) and while (r - l > 1)?At first glance it seems like the second variant somehow helps to avoid an infinite loop, but I am not sure.
•  » » » 7 years ago, # ^ |   +9 Consider that during the execution of binary search we have at some instant, r=l+1. Most implementations have mid=(l+r)/2 . Thus, mid=l. Now, if the check condition for the binary search evaluates to false for mid=l and if we are looking for the upper bound, the update would then be l=mid. This would lead to an infinite loop.I believe it could be avoided if the update step is l=mid+1.
 » 7 years ago, # |   +8 What's wrong with Div1E and Div1F editorials?For Div1F it shows Tutorial is not available, just code.For Div1E there is an explanation why users should rate the blog post in non-decreasing order, it ends with Now, suppose and then code is provided. It seems incomplete.
•  » » 7 years ago, # ^ |   +2 Thank you, fixed.
 » 7 years ago, # | ← Rev. 3 →   0 Question about Div1EHow can we set up a sorted collection of users that supports insertion (or deletion instead) and final blog-post rating calculation in O(log(N)) time or less?UPD: Now solution described in editorial is clear for me.
 » 7 years ago, # | ← Rev. 2 →   0 Funny solution for DIV2B, O(1) (??) (binary search on array of 25 elements + some O(1) operations) : 26939967
•  » » 7 years ago, # ^ |   0 Lol..! It can be done but actually you don't get time during competition to make such a matrix or say table.
 » 7 years ago, # | ← Rev. 3 →   +1 Can anyone help with this statement related to Div.2 problem C ? Why does t have to be less than or equal to y here ?"It can be proved that one "very large" value of t is t = y — that is, if the inequalities are not satisfied for t = y, then they cannot be satisfied for any value of t."
•  » » 7 years ago, # ^ |   0 That was the only bug in my code during the contest. I took t up to 1e18. What I can see is q>=p and increasing t will anyhow increase the difference between numerator and denominator. Please help.
•  » » » 7 years ago, # ^ |   0 Same :(
•  » » 7 years ago, # ^ |   +10 Here the inequality is t(q-p)>=y-x. If t==y then y(q-p) is clearly greater than y-x when p!=q and x!=y. if x==y and p==q then it will be y(q-p)=y-x=0.
•  » » 7 years ago, # ^ |   0 We are trying to make the following hold: pt>=x and qt >= y if t=y, then both of the conditions above will hold. Since x <= y, then x <= y*p for a positive integer p. (we can handle p=0, separately). y <= y * q where q is a positive integer. Since we are trying to find the smallest possible value for t, then we can use y as an upper bound on t.
 » 7 years ago, # |   -6 excuse me ! i was just wondering if Div 2 C problem can be solved by Extended Euclid Algorithm ? what i am doing is following let a be the number of Successful hacks and b the number of unsuccessful ones now if hack is successful i will increase the numerator by a it would be x+a,,and denominator would be increased also by y+aif hack is unsuccessful denominator only will be increased by b then it would become y+a+btrue: x+a/y+a+b=p/q then -->(q*x)+(q*a)=(y*p)+(a*p)+(b*p) make it as linear equation and solve it by Extended Euclid Algorithm i don't know if is it right or wrong ? what is your opinion i have some problem with Extended Euclid Algorithm so i can't implement clearly but mathematically i think it's right
•  » » 7 years ago, # ^ |   0 Yes, we can solve div2C with this approach.Here is my code: 26955095
 » 7 years ago, # |   0 For Div1 C (prairie partition ) question. I tried to first satisfy all non 2 power k forms with requirements.And later tried to check if m was satisfiable or not greedily. I think I cannot describe it properly in words. So here is the code. Can someone provide a simple counter case for this approach.
 » 7 years ago, # |   +10 In problem DIV2B, in each iteration for s, we can increment it by 50, rather than 1.
 » 7 years ago, # |   +6 Can you explain for me the sentence is bolded ? Consider an optimal solution, and let k be the smallest index with wk = 0. Let's prove that for all i ≤ k - 3 we have wi > wi + 1. Indeed, assume that for some i ≤ k - 3 we have wi ≤ wi + 1. Then, since the graph is complete, we can replace the i + 1-th edge with an edge directing to an endpoint of any 0-perishability road, and the i + 2-th edge with this 0-perishability road. In this case, the minimized sum will become smaller, which is a contradiction to our solution being optimal.I don't understand it.
•  » » 7 years ago, # ^ |   0 Regardless of the weight of w(i+1), the perishability of the route from the museum to (i+1)th cities will not be affected (because w(i)=w(i)).
•  » » 7 years ago, # ^ |   +44 Consider an example. Suppose our optimal solution is: M <------- A <------- B <------- C <------- D <------- E <------- F <------- G ... 23 11 4 7 3 1 0 Here, M is the museum city. In this case, we have w = (23, 11, 4, 7, 3, 1, 0, ...). Note that we don't care about what comes after 0, since route perishabilities for all cities starting with G will be 0. The sought sum will be equal to 23 + 11 + 4 + 4 + 3 + 1 = 46.Now, observe that k = 7, so we know that F-G is a 0-perishability road, but w3 = 4 ≤ 7 = w4. Then I claim that our solution can't be optimal, because the following solution will be better: M <------- A <------- B <------- C <------- F <------- G ... 23 11 4 x 0 That is, we replace the 4-th road with a road directing to F, and F is an endpoint of a 0-perishability road, then we replace the 5-th road with this 0-perishability road itself.Note that we don't know road C-F perishability, but we know that this road exists, which is enough. The sought sum will be 23 + 11 + 4 + min(4, x) ≤ 42.
•  » » » 7 years ago, # ^ |   0 hi, can u pls explain the 2nd case of this para:Then, we have two options: either Wk - 2 > Wk - 1 or Wk - 2 ≤ Wk - 1. In 1st case i got that ans will be sum of peris' till before kth road. pls verify but have problem understanding 2nd one. i do not get possible position of X and which two roads. thanks 
•  » » » 7 years ago, # ^ |   0 Thank you. I understood !
 » 7 years ago, # |   0 For Div2D. I copied the solution but it does not pass on a test. Here it is: 26977808. Can you please tell me where is the mistake?
•  » » 7 years ago, # ^ |   +1 You are 1-indexing your arrays of size m. The out of bounds access causes undefined behaviour.
•  » » » 7 years ago, # ^ |   0 I modified that and it still gives me wrong answer on test 15.
•  » » » » 7 years ago, # ^ |   +35 In your line  for(int bots = 0; bots < ((1 << (k - 1)) - 1) * n; bots++) replace < with <=. The bound of 31n new accounts is tight.
•  » » » » » 7 years ago, # ^ |   0 Why would I get RUNTIME_ERROR on test 7 after replacing < with <= ? 26994891
•  » » » » » » 7 years ago, # ^ |   +53 Because you've also replaced N = 120 with N = 12.
•  » » » » » » 7 years ago, # ^ | ← Rev. 2 →   +11 Next time, you can use the "Compare" feature to figure out what changed in between submissions.
 » 7 years ago, # |   0 Excuse me, I had to ask:Div2A states that No two participants have the same number of points, but the test cases include otherwise. Have I missed something?
•  » » 7 years ago, # ^ |   +22 I guess it's a bit ambiguous, but this statement is about the round points, not about the rating points. It implies that no two participants took the same place in the round.
 » 7 years ago, # | ← Rev. 2 →   0 Thank you
 » 7 years ago, # |   0 DIV2 D using binary search on multiple intervals. CODE.
 » 5 years ago, # |   0 Can anyone give the proof for the t=y fact given in Div2C/Div1A editorial?
•  » » 5 years ago, # ^ |   +10 Let 's' be the number of successful submissions and 'u' be the number of unsuccessful submissions that you added. So, s + x = pt => s = pt — x and y + s + u = qt => u = qt — s — y = qt — (pt — x) — y = t(q-p) — (y-x). So we get s = pt — x and u = t(q-p) — (y-x) clearly s>=0 is impossible when (p==0) and (x!=0). And u>=0 is impossible when (p==q) and (y!=x). So we weed out those possibilities. From the first equation we need t to satisfy pt>=x. In this case, the minimum possible t is the highest when p = 1. Thus the highest minimum possible t is x. From the second equation we need t to satisfy t(q-p)>=(y-x). In this case, the minimum possible t is highest when q-p=1. Thus the highest minimum possible t is y-x.From the above two facts we can say that t never goes higher than max(x,y-x). Since, y>=max(x,y-x) we can say that t never goes above y. I have implemented this idea in my submission — 62595664
 » 15 months ago, # | ← Rev. 2 →   0 Hey tourist, I have basically brute-forced div1-D and I am not quite sure what its actual time complexity is : LinkI am basically running dijkstras from each source, and I just stop the loop whenever the distance till the current node becomes greater than the answer (till that node), and I also restrict the relaxations by firstly sorting the adjacency list of each node in increasing order of weight and ensuring that all the paths are monotonically decreasing in terms of edge weight.It should be $O(N^3.\log{N})$, but I ran some stress tests too, and it always seems to stop really early.