tourist's blog

By tourist, history, 6 months 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
 
 
 
 
  • Vote: I like it  
  • +570
  • Vote: I do not like it  

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

O(1) solution for DIV2C. Code

  • »
    »
    6 months 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.

    • »
      »
      »
      6 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      in this problem what is the means of this line of code

      if (s % 50 != x % 50) {
        continue;
      }
      • »
        »
        »
        »
        6 months ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        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

    • »
      »
      »
      6 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I guess it is O(T) to be presize.)

    • »
      »
      »
      5 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Thnks

  • »
    »
    6 months ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it
    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

    • »
      »
      »
      5 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      shouldnt k>=(y/q) instead of k>=(p/q)?

»
6 months 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 ?

  • »
    »
    6 months 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.

    • »
      »
      »
      6 months 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 ?

      • »
        »
        »
        »
        6 months 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.

»
6 months 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

  • »
    »
    6 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    i created this solution exactly and i have the same question xD

  • »
    »
    6 months 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 :)

»
6 months 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"

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

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

  • »
    »
    6 months 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.

»
6 months 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.

  • »
    »
    6 months 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.

»
6 months 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.

  • »
    »
    6 months ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    Naturally, he will get 2000·(1 - 0 / 250) = 2000 points.

»
6 months ago, # |
Rev. 2   Vote: I like it -99 Vote: I do not like it

.

»
6 months 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)

  • »
    »
    6 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Binary search, google it.

    • »
      »
      »
      6 months 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)

  • »
    »
    6 months 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.

    • »
      »
      »
      6 months 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.

»
6 months 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.

»
6 months 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.

»
6 months 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

  • »
    »
    6 months 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.

»
6 months 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."

  • »
    »
    6 months 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.

  • »
    »
    6 months 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.

  • »
    »
    6 months 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.

»
6 months 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

»
6 months 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.

»
6 months 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.

»
6 months 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.

  • »
    »
    6 months 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)).

  • »
    »
    6 months 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.

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

      Thank you. I understood !

»
6 months 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?

  • »
    »
    6 months 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.

    • »
      »
      »
      6 months 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.

      • »
        »
        »
        »
        6 months 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.

        • »
          »
          »
          »
          »
          6 months 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

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

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

          • »
            »
            »
            »
            »
            »
            6 months 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.

»
6 months 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?

  • »
    »
    6 months 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.

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

Thank you

»
6 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
6 months ago, # |
  Vote: I like it 0 Vote: I do not like it

DIV2 D using binary search on multiple intervals. CODE.

»
6 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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?