Блог пользователя tourist

Автор tourist, история, 7 лет назад, По-русски

Разбор задач VK Cup 2017 Round 3 и Codeforces Round #412 доступен на русском и английском языках. Приятного прочтения!

Is it rated?
T-Shirt Hunt
Success Rate
Dynamic Problem Scoring
Prairie Partition
Perishable Roads
Blog Post Rating
Test Data Generation
Разбор задач VK Cup 2017 - Раунд 3
  • Проголосовать: нравится
  • +570
  • Проголосовать: не нравится

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

O(1) solution for DIV2C. Code

»
7 лет назад, # |
  Проголосовать: нравится 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 лет назад, # ^ |
      Проголосовать: нравится +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 лет назад, # ^ |
        Проголосовать: нравится 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 лет назад, # ^ |
          Проголосовать: нравится +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 лет назад, # |
  Проголосовать: нравится +5 Проголосовать: не нравится

How to solve Div2C this way? From (x+c)/(x+c+d)=p/q , we have qx+qc=px+pc+pd => qx-py = p(c+d) — qc ,where (qx-py)=s => So we have Linear Diophantine eqution where (c+d) and c are unknowns. So is it possible to solve problem this way and how would it be implemented?

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +8 Проголосовать: не нравится

    You can check, that solution (c, c + d) = ( - x0,  - y0) obviously works. After that, since we have Diophantine equation qa - pb = s with coprime coefficients q and p, each solution can be written as a =  - x0 + k × p, b =  - y0 + k × q, it solves the problem.

»
7 лет назад, # |
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 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

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

»
7 лет назад, # |
  Проголосовать: нравится +15 Проголосовать: не нравится

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

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

»
7 лет назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится

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

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +33 Проголосовать: не нравится

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

»
7 лет назад, # |
  Проголосовать: нравится 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 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Binary search, google it.

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 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 лет назад, # ^ |
        Проголосовать: нравится +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 лет назад, # |
  Проголосовать: нравится +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 лет назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

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

»
7 лет назад, # |
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 лет назад, # ^ |
      Проголосовать: нравится 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 лет назад, # ^ |
      Проголосовать: нравится +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 лет назад, # ^ |
      Проголосовать: нравится 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 лет назад, # |
  Проголосовать: нравится -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+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

»
7 лет назад, # |
  Проголосовать: нравится 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 лет назад, # |
  Проголосовать: нравится +10 Проголосовать: не нравится

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

»
7 лет назад, # |
  Проголосовать: нравится +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 лет назад, # ^ |
      Проголосовать: нравится 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+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)).

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +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 лет назад, # ^ |
        Проголосовать: нравится 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 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      Thank you. I understood !

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится +20 Проголосовать: не нравится

В задаче Div 1 B можно использовать бинарный поиск по ответу.

Заметим, что значение функции f(x — y), где x это сумма баллов Васи, а y — сумма баллов Пети, будет возрастать на промежутках. Можно запустить бинарный поиск на каждом промежутке и взять лучший ответ.

Границы промежутков можно найти таким образом. Рассмотрим на примере одной из задач. Первое замечание состоит в том, что задача будет уменьшать значение функции только если Вася её не решил, а Петя решил. Найдём все возможные количества людей k такие, что добавив k человек к соревнованию изменится стоимость задачи. Заметим, что таких значений k будет не больше log(n), где n это изначальное количество участников. Найдя все значения k для всех задач мы и найдём границы всех возрастающий промежутков функции.

Итоговая асимптотика: O(n + log(n) * log(n))

Код к задаче: 26941734

  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится +50 Проголосовать: не нравится

    Есть и другой вариант. Если находить k для всех задач, а не только для решённых Васей и нерешённых Петей, то можно обойтись без бинпоиска — достаточно проверить 0 и все такие k в качестве ответа.

    Такое решение можно получить, добавив в код 12 символов /.

    Найди 12 отличий
»
7 лет назад, # |
  Проголосовать: нравится 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 лет назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

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

    • »
      »
      »
      7 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

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

      • »
        »
        »
        »
        7 лет назад, # ^ |
          Проголосовать: нравится +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 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

in 807B what is the means of this line of code

if (s % 50 != x % 50) {
  continue;
}
  • »
    »
    7 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    The following line in the tutorial explains it:

    Moreover, since hacks change our score only by multiples of 50, the difference s  -  x has to be divisible by 50.

    s - x being divisible by 50 is equivalent to s and x having the same remainder of division by 50.

»
7 лет назад, # |
  Проголосовать: нравится 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 лет назад, # ^ |
      Проголосовать: нравится +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 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

Thank you

»
7 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

DIV2 D using binary search on multiple intervals. CODE.

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +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

»
12 месяцев назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

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.