### tourist's blog

By tourist, history, 2 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  Comments (65)
 » 2 years ago, # | ← Rev. 2 →   O(1) solution for DIV2C. Code
•  » » A bit simpler O(1) solution is described as the second solution in the tutorial.
•  » » » in this problem what is the means of this line of code if (s % 50 != x % 50) { continue; }
•  » » » » Checking if the difference between s and x is divisible by 50 or not. If not, we are not interested in that value of s
•  » » » I guess it is O(T) to be presize.)
•  » » » Thnks
•  » » 2 years ago, # ^ | ← Rev. 2 →   O(1) solution: Let m successful and n unsuccessful submissions then (x+m)/(y+m+n)=k*p/k*q => x+m=k*p and y+m+n=k*q => k*p-x >= 0 (as m>=0) and k*q-y >=0 (as m+n>=0) => k>=x/p and k>=p/q also, y+n-x=k*(q-p) (subtracting two equations) => n=k*(q-p) - (y-x) >=0 => k>= (y-x)/(q-p) therefore, k=max(x/p,p/q,(y-x)/(q-p)) thus, ans=m+n = k*q-y My submission — 27361138
•  » » » shouldnt k>=(y/q) instead of k>=(p/q)?
 » 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 ?
•  » » 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.
•  » » » 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 ?
•  » » » » 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.
 » 2 years ago, # | ← Rev. 2 →   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
•  » » i created this solution exactly and i have the same question xD
•  » » 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 :)
 » for (int bots = 0; bots <= ((1 << k) — 1) * n; bots++) {In the code of 806B — Dynamic Problem Scoring, the '+' is gone as "&mdash"
•  » » 2 years ago, # ^ | ← Rev. 2 →   Presumably it's a - (a dash), not a +.
•  » » Yes, it was meant to be a minus, not a plus :) Not sure why it transformed into "—". Fixed.
 » Why the editorial is not appearing in contest page or announcement page? Please add link.
•  » » Thank you, added the link to the announcement page. It will appear on the contest page shortly.
 » 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.
•  » » Naturally, he will get 2000·(1 - 0 / 250) = 2000 points.
•  » » » Sorry my bad.
 » 2 years ago, # | ← Rev. 2 →   .
•  » » 2 years ago, # ^ | ← Rev. 2 →   n
 » For div2/C why do we have to put while(r-l>1)
•  » » Binary search, google it.
•  » » » Binary search says while(l while(r-l>0) not while(r-l>1)
•  » » » » No difference, It is the same.
•  » » 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.
•  » » » 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.
 » 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.
•  » » Thank you, fixed.
 » 2 years ago, # | ← Rev. 3 →   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.
 » 2 years ago, # | ← Rev. 2 →   Funny solution for DIV2B, O(1) (??) (binary search on array of 25 elements + some O(1) operations) : 26939967
•  » » Lol..! It can be done but actually you don't get time during competition to make such a matrix or say table.
 » 2 years ago, # | ← Rev. 3 →   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."
•  » » 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.
•  » » » Same :(
•  » » 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.
•  » » 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.
 » 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
•  » » Yes, we can solve div2C with this approach.Here is my code: 26955095
 » 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.
 » In problem DIV2B, in each iteration for s, we can increment it by 50, rather than 1.
 » 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.
•  » » 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)).
•  » » 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.
•  » » » 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 
•  » » » Thank you. I understood !
 » 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?
•  » » You are 1-indexing your arrays of size m. The out of bounds access causes undefined behaviour.
•  » » » I modified that and it still gives me wrong answer on test 15.
•  » » » » In your line  for(int bots = 0; bots < ((1 << (k - 1)) - 1) * n; bots++) replace < with <=. The bound of 31n new accounts is tight.
•  » » » » » Why would I get RUNTIME_ERROR on test 7 after replacing < with <= ? 26994891
•  » » » » » » Because you've also replaced N = 120 with N = 12.
•  » » » » » » 2 years ago, # ^ | ← Rev. 2 → Next time, you can use the "Compare" feature to figure out what changed in between submissions.
•  » » » » » » » Thank you both!
 » 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?
•  » » 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.
 » 2 years ago, # | ← Rev. 2 →   Thank you
 » In problem A — Div 2, it says, "It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed." __But it does not mentions that which rating we have to consider for comparing, the rating before the contest or the rating after the contest. Or it's just that I have understood it in the wrong way.!
 » DIV2 D using binary search on multiple intervals. CODE.
 » For Div2 B: for up in range(500): for down in range(500): if x + 100 * up - 50 * down >= y and check(x + 100 * up - 50 * down): print(up) exit() Im sorry but how do you know the range is 500? Can someone specify this?
 » Can anyone give the proof for the t=y fact given in Div2C/Div1A editorial?