tourist's blog

By tourist, history, 8 years ago, translation, In English

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
Perishable Roads
Blog Post Rating
Test Data Generation
Tutorial of VK Cup 2017 - Round 3
  • Vote: I like it
  • +570
  • Vote: I do not like it

| Write comment?
»
8 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

O(1) solution for DIV2C. Code

  • »
    »
    8 years ago, # ^ |
      Vote: I like it +172 Vote: I do not like it

    A bit simpler O(1) solution is described as the second solution in the tutorial.

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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 ?

  • »
    »
    8 years ago, # ^ |
      Vote: I like it +95 Vote: I do not like it

    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.

    • »
      »
      »
      8 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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 ?

      • »
        »
        »
        »
        8 years ago, # ^ |
          Vote: I like it +78 Vote: I do not like it

        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.

»
8 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I tried to do that. Here is my attempt 26939775

    It 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 :)

»
8 years ago, # |
  Vote: I like it +15 Vote: I do not like it

for (int bots = 0; bots <= ((1 << k) &mdash; 1) * n; bots++) {

In the code of 806B — Dynamic Problem Scoring, the '+' is gone as "&mdash"

  • »
    »
    8 years ago, # ^ |
    Rev. 2   Vote: I like it +15 Vote: I do not like it

    Presumably it's a - (a dash), not a +.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it +54 Vote: I do not like it

    Yes, it was meant to be a minus, not a plus :) Not sure why it transformed into "&mdash;". Fixed.

»
8 years ago, # |
  Vote: I like it +6 Vote: I do not like it

Why the editorial is not appearing in contest page or announcement page? Please add link.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it +33 Vote: I do not like it

    Thank you, added the link to the announcement page. It will appear on the contest page shortly.

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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.

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

For div2/C why do we have to put while(r-l>1)

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Binary search, google it.

    • »
      »
      »
      8 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Binary search says while(l<r) <=> while(r-l>0) not while(r-l>1)

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.

    • »
      »
      »
      8 years ago, # ^ |
        Vote: I like it +9 Vote: I do not like it

      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.

»
8 years ago, # |
  Vote: I like it +8 Vote: I do not like it

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.

»
8 years ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

Question about Div1E

How 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.

»
8 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Funny solution for DIV2B, O(1) (??) (binary search on array of 25 elements + some O(1) operations) : 26939967

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Lol..! It can be done but actually you don't get time during competition to make such a matrix or say table.

»
8 years ago, # |
Rev. 3   Vote: I like it +1 Vote: I do not like it

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."

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    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.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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.

»
8 years ago, # |
  Vote: I like it -6 Vote: I do not like it

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+a
if hack is unsuccessful denominator only will be increased by b then it would become y+a+b

true: 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

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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.

»
8 years ago, # |
  Vote: I like it +10 Vote: I do not like it

In problem DIV2B, in each iteration for s, we can increment it by 50, rather than 1.

»
8 years ago, # |
  Vote: I like it +6 Vote: I do not like it

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.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like 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+1)). Therefore it is legit to change the (i+1)th. From the (i+2)th cities, the perishability is always zero. Therefore, we jump to a not worse solution (just in case w(i+1)>=w(i)).

  • »
    »
    8 years ago, # ^ |
      Vote: I like it +44 Vote: I do not like it

    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.

    • »
      »
      »
      8 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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
      
    • »
      »
      »
      8 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thank you. I understood !

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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?

  • »
    »
    8 years ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    You are 1-indexing your arrays of size m. The out of bounds access causes undefined behaviour.

    • »
      »
      »
      8 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I modified that and it still gives me wrong answer on test 15.

      • »
        »
        »
        »
        8 years ago, # ^ |
          Vote: I like it +35 Vote: I do not like it

        In your line

         for(int bots = 0; bots < ((1 << (k - 1)) - 1) * n; bots++)
        

        replace < with <=. The bound of 31n new accounts is tight.

        • »
          »
          »
          »
          »
          8 years ago, # ^ |
            Vote: I like it 0 Vote: I do not like it

          Why would I get RUNTIME_ERROR on test 7 after replacing < with <= ? 26994891

          • »
            »
            »
            »
            »
            »
            8 years ago, # ^ |
              Vote: I like it +53 Vote: I do not like it

            Because you've also replaced N = 120 with N = 12.

          • »
            »
            »
            »
            »
            »
            8 years ago, # ^ |
            Rev. 2   Vote: I like it +11 Vote: I do not like it

            Next time, you can use the "Compare" feature to figure out what changed in between submissions.

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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?

  • »
    »
    8 years ago, # ^ |
      Vote: I like it +22 Vote: I do not like it

    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.

»
8 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Thank you

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

DIV2 D using binary search on multiple intervals. CODE.

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Can anyone give the proof for the t=y fact given in Div2C/Div1A editorial?

  • »
    »
    5 years ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    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

»
20 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Hey tourist, I have basically brute-forced div1-D and I am not quite sure what its actual time complexity is : Link

I 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.