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

Автор okwedook, 12 месяцев назад, перевод, По-русски

Все задачи названы в честь песен моей любимой группы Hippie Sabotage. Рекомендую их послушать!

1826A - Trust Nobody

Подсказка1
Подсказка2
Решение

C++ реализация: 204718333

1826B - Lunatic Never Content

Подсказка1
Подсказка2
Решение

C++ реализация: 204718497

1826C - Dreaming of Freedom

Подсказка1
Подсказка2
Подсказка3
Решение

C++ реализация: 204718535

1826D - Running Miles

Подсказка1
Подсказка2
Решение

C++ реализация: 204718553

1826E - Walk the Runway

Подсказка1
Подсказка2
Подсказка3
Решение

C++ реализация: 204718603

1826F - Fading into Fog

Подсказка1
Подсказка2
Подсказка3
Решение

C++ реализация: 204718641

Разбор задач Codeforces Round 870 (Div. 2)
  • Проголосовать: нравится
  • +165
  • Проголосовать: не нравится

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

instant editorial

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

What? Hints are in Russian and solutions are in English.

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

I'll add implementations as soon as system testing finishes.

Thanks for participation, I hope you liked the contest even though problem A was kinda hard.

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

In Problem F, was the inaccuracy 1e-4 in projection set deliberately? Maybe the projection point is fairly accurate, but the judge adds a random number smaller than 1e-4. Otherwise It's simple to find all points by y=0, y=-0.001x (2 queries).

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

    Yes, it was set deliberately The interactor simply adds noise to the answer

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

    By the way, can we add line $$$x=0$$$ here and be alright? This way, we will have precise enough values of candidate ys (which are well spread apart), and then we can just match.

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

    Does a 2 query solution pass? I am not sure why you needed to add weird constraints and inaccuracy

    +) I think the editorial for 'getting rid of noise' part is needed

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

      May be because getting rid of noise is a part of the problem difficulty, otherwise, the problem is too easy to be placed in F.

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

I wrote a strange solutino for E and not sure if it will FST.

I notice that the bottleneck is calculating the relationship of (i, j), it's O(m) originally. The whole algorithm is O(n^2m). So I add two optimization strategies:

  • When the transition can be from F[i] to F[j], I ommit the nodes of the solution chain of F[i]. This may be hack by this array:

1 2 3 4 5

1 2 3 4 5

...

1 2 3 4 5

1 1 1 1 1

  • So I add another strategy: If [line x] causes j to be unable to connect to i. The next link judgement will start from [line x].

https://mirror.codeforces.com/contest/1826/submission/204635663

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

shit as predickted

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

Worst div.2 that I've ever participated in.

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

    nice, you cant solve proplems and and you say its the authors fault

    • »
      »
      »
      12 месяцев назад, # ^ |
        Проголосовать: нравится -34 Проголосовать: не нравится

      I have given quite a few contests(60+) which is more than twice of what you have given and yet it's my first time commenting something like this. There has to be a reason for this no?

      I did not say it because of my bad performance, I said it because of the imbalance in the problems.You can see that B has more accepted solutions than A and the number of accepted solutions of A and C are comparable. This is not the usual case.

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

        I have given more contests than you and I say it was a good contest and a nice problem set. Thank you authors for the nice problems.

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

          I don't trust your nickname

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

            Haha. It's just personal preference. Though I suck a lot at math I still love it.

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

          It's not about giving more contests , I said it to show that I don't do comments like these after every contest. And I have given quite a few.

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

        There are about 7000 solutions on a and about 6000 on c, maybe its really hard for a div2, but everybody can solve it, maybe not for 5 minutes as usual. As for c it is easier than usual, and you also could solve it, but you didnt and now you tell me that there is something wrong with the contest.bruh

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

Is D can be solved using ternary search ?

Isnt it f(len) = max1+max2+max3+len for all length a convex function

I tried during contest but couldnt do. Can somebody let me know whether i am correct or not

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

Problem B is from past contests.

Problem Link: https://mirror.codeforces.com/gym/102035/problem/I

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

In $$$B$$$, it should be "which basically says $$$x$$$ divides $$$a_i−a_{n−i+1}$$$"

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

You can solve problem 1826E - Walk the Runway in $$$O\left(n^2 \times m\right)$$$ in C++ without bitsets. Based on naive $$$O\left(n^2 \times m\right)$$$ approach, you need to apply next optimizations one-by-one for getting 1872 ms.

Optimization 1
Optimization 2
Optimization 3
Optimization 4

Accepted 1872 ms submission

  • »
    »
    12 месяцев назад, # ^ |
    Rev. 3   Проголосовать: нравится +19 Проголосовать: не нравится

    Optimization 1 is redundant, this part of solution takes less then 100 ms.

    __restrict keyword is also unnecessary, your code doesn't change arrays.

    I tried to use similar approach but didn't came up with genius optimization 2.

    I changed your check function a little bit, now solution is 1263 ms :)

    204651252

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

      Thank you, idea with unsigned difference instead of comparison is very cool too.

      I think 1263 ms is not so fair, because during system testing a lot of solutions are running simultaneously on same cpu with common L3 cache (L2 and L1 are isolated and are private for each core) and more likely that someone will push out your data from L3 cache, then it will be pushed out of L2, then will be pushed out of L1, because it is required for data to be in cache of higher level. But I can be wrong.

      I remember that runtime of my original solution was 1200 ms in the custom invocation during a contest with m = 5000, n = 500 and each row is sorted permutation, but it became 1700 ms after submit (pretests) and 1872 ms during system testing.

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

        I tried to submit both versions within a second (obviously not during contest). I even tried to return back "restrict" keyword in my version. I repeated it 3 times. Here are results. Rather unstable but highest bit trick tends to be faster.

        Screenshot

        I think cache is not a bottleneck here. The main optimization is SIMD usage. uint16_t helps to do more operations per vector instruction.

        Why highest bit trick is faster? Well, I guess sometimes bool type behaves in other manner. Like a widely known fact that construction "if (a && b)" for many compilers is actually "if (a) if (b)". I remember in some video a guy explained if you want your SIMD to work properly use bool very carefully :)

        About 1200 ms on sorted max test — maybe branch predictor memorized this simple pattern and helped to reduce time in some way (I'm not sure, just an assumption).

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

I think my solution for D is different, and slightly over-complicated comparing the editorial.

I thought of the array being empty first and then I put the elements from higher to lower beauty in their position, at each iteration, the answer is to choose the best three consecutive sights, they are consecutive because the answer has the three most beautiful sights in some [l, r], when the minimum of them is put in the array, they are consecutive because there is nothing between them. Finally adding one sight to the array creates only three new trios of new possible consecutive sights, (e. g. m is the index of the new sight [a, b, m, c, d], the new three consecutive trios are [a, b, m], [b, m, c] and [m, c, d]), so I represented the dynamic array with sets, and check the three new possible trios after I put an element in the array.

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

    I think you could have implemented it easier if you would have maintained 2 arrays of neighbours (l[i] = left neighbour of i, r[i] = right neighbour of i). Initialise the arrays with the 3 biggest numbers. When you have to add a number x on position i you use the positions of the closest to left (lPos) and the closest to right (rPos) elements greater than or equal to x (that are visited already) and update l and r arrays accordingly ( l[i] = lPos l[lPos] = i etc.). Next you take 2 elements from the left and 2 from the right using these arrays and do the answer updates. There are some edge cases on the margins but can be easily handled by adding dummy numbers.

    As a side note, I like your idea:)

»
12 месяцев назад, # |
Rev. 2   Проголосовать: нравится -10 Проголосовать: не нравится
so the total time complexity would be O(n2m/64)
, which is fast enough.

So why my solution of E 204620376 got TLE?

Update: Now I optimized it in 204648297

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

To my mind, if there was problem E instead of problem D (but with smaller constants,like m<=100, n<=1000), this contest would be much better. Cause D is too easy for this position, and E is quite easy too (comparing to other "E" problems)

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

Why is this submission getting Idleness Limit Exceeded on Test 120?

EDIT: replacing 0.0002 with 0.0002004 gives AC :(

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

You can solve problem D even if instead of finding 3 best elements we had to find k best elements in time complexity of O(k*nlogn). For finding best two, you can do the following : For all i, first insert a[i]-i in the set. Now iterate on i from left to right, erase a[i]-i from set and find maximum value in set(mx) and set b[i] = a[i]+mx+i. b[i] now contains the answer for maximum 2 values. Now you repeat this by inserting b[i]-i and setting as c[i] = a[i]+mx+i again. Repeating this allows to pick k best elements in O(k*nlogn)

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

    Nice variant!

    I think this can be optimized into O(NK) time: define $$$s(j, l) = max (A[i_1] - i_1 + A[i_2] + A[i_3] + ... + A[i_l])$$$ for any $$$i_1 < i_2 < ... < i_l < j$$$ (that is: the maximum value of a subsequence of length $$$l$$$ using elements before $$$j$$$ and baking in the $$$+ l$$$ term). Then the answer is $$$max(s(j, K-1) + A_j - j)$$$ over all possible values of $$$j$$$ ($$$1 < j < N$$$).

    We can go through the array from left to right and calculate $$$s(j, l) = max(s(j - 1, l), s(j - 1, l - 1) + A_j$$$ in O(K-1) time, for an $$$O(NK)$$$ time and $$$O(K)$$$ space solution.

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

      i did it in linear time by computing prefix and suffix maximums of of a[i]+i and a[i]-i respectively. and then iterating from 2nd to last second sight 204718856. i wonder how can we solve this using DP, not very good at it ;-;

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

      We can go through the array from left to right and calculate ... in O(K-1) time, for an O(NK) time and O(K) space solution.

      Won't we iterate from right to left for O(K) space solution?

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

What is the fairly straightforward solution using DP for D mentioned in the editorial?

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

    DP method uses the same idea: two of the three biggest values are in left and right boundary. Otherwise we will shorten the range and get smaller cost.

    f[i][j] is the answer of choosing j numbers in first i of n numbers. 0<=j<=3.

    the cost -(R-L)=L-R can be added into calculation in running process.

    When the first number is selected, left boundary L is fixed to its index. This is f[i][0]->f[i][1], add index i(=L) to answer additionally.

    When the third number is selected, right boundary R is fixed to its index. This is f[i][2]->f[i][3], subtract index i(=R) to answer additionally.

    The method can be expanded to selecting k numbers rather than 3 numbers, with time O(nk).

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

Thank you for preparing for this round, despite the A problem is hard than B,C hh:)

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

Wow, editorials come so fast...

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

In problem C,

First we need to notice, that in order to keep some amount of options indefinetely, this number has to be at least 2 and divide n.

How to prove that number d divide n ?

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

    Each person casts exactly $$$1$$$ vote. If there are $$$m$$$ options and $$$n$$$ people voting, then for all options to be kept, they must all receive an equal number of votes, $$$k$$$. That means $$$km = n$$$, or equivalently, $$$n$$$ is a multiple of $$$m$$$, or equivalently, $$$m$$$ is a divisor of $$$n$$$.

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

      Thanks! i misread the problem and wasn't considering no matter how people vote, now i got it.

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

      In this i am doing same but then also i got WA why?

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

      "every programmer makes a vote for one of the remaining algorithms", so all the m algorithms has to be voted first or atleast once in each round, then how does it effect when m>=d ? I think doing this could work : if(n==1 || m==1){ opnl("YES"); return; } if(n<=m){ opnl("NO"); return; } if(n%m == 0){ opnl("NO"); return; } while(n%m>1){ m = n%m; } if(n%m==0){ opnl("NO"); }else{ opnl("YES"); }

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

I have a different solution for D. I solved it using the divide and conquer method. I must select three elements that maximize the answer from 1 to n. At first, I divided the range into two equal segments 1 to n/2 and n/2+1 to n. Now, there are four cases. 1. All three elements are on the right side. In this case, we have to solve it for the range n/2+1 to n. 2. All three elements are on the left side. In this case, we have to solve it for the range 1 to n/2. 3. Two elements are in the left segment and another one is in the right segment. 4. Two elements are in the right segment and another one is in the left segment. I have to take the maximum of these four results. For case 3 one element is on the right side. I have iterated over the right segment for the element. If I take ith element it will make profit li and to take this element I have to travel i-n/2 miles. So, the ultimate profit is li-(i-n/2). I took the element which makes the maximum profit. For the left segment, there are two elements. I have iterated over the left segment. If the ith element is the first element of the two elements then I have to travel n/2-i miles. I will take the maximum two elements x and y from the i to n/2 range. Then it will make a profit of x+y-(n/2-i). I have chosen that make maximum profit. Case 4 is similar to Case 3. The complexity is O(nlogn). Here is my solution. https://mirror.codeforces.com/contest/1826/submission/204653388

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

19k registrations and only 5k participants nice A ;)

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

Problem D can be solved easily without precalculating anything. In fact, it can be solved in O(1) space and O(N) time: https://www.codeforces.com/contest/1826/submission/204656798

The logic is similar to the editorial. We rewrite the problem as: maximize $$$(A_i + i) + A_j + (A_k - k)$$$ subject to $$$i < j < k$$$. Then we can run the values $$$k$$$ from 1 through N, and keep track of the maximum values of $$$A[i] + i$$$ and the maximum value of $$$(A_i + i) + A_j$$$ (see the code for details) at each position.

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

    It's the same DP but you used k-1 = 2 variables to store dp[i][1], dp[i][2] and "answer" to store dp[i][3]

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

Problem E has weak tests because some AC submissions used random or checked if 50-100 comparisons were ok, while there are 500 needed.

I've added one test to hack these submissions but its still not ok, i guess.

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

in Ques A why not l(i)>=x as at least x can be no of liers ,, as in editorial its l(i)>x

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

okwedook I still don't understand why 2 queries aren't enough in F. Is it not ok to get the x coordinates through projection on y = 0 and y coordinates through projection on x = 0? It is also written that ans should be correct till 3 decimal places and since the noise is < 10−4 for each point through the query, shouldn't we be good?

  • »
    »
    12 месяцев назад, # ^ |
    Rev. 5   Проголосовать: нравится +8 Проголосовать: не нравится

    From the statement:

    In one query, you can ask some line ax+by+c=0 and get the projections of all n points to this line in some order

    The points are not nescessarily returned in the same order every time. Thus, the two following cases are indistinguishable from each other with just queries $$$x = 0$$$ and $$$y = 0$$$:

    For both of these cases you could recieve the following answers:

    $$$x = 0 \ \Rightarrow \ 0\ 1\ 0\ 2$$$

    $$$y = 0 \ \Rightarrow \ 1\ 0\ 2\ 0$$$

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

Am I the only one not getting the solution of A? :(

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

    This much is obvious that the number of liars can range anywhere between [0, n] inclusive. Say the no. of liars is L.

    From the statement: Some of them might be liars, who always tell lies. The i-th person says "There are at least L liars amongst us".

    Since liars always tell lies, they will surely say that the no. of liars are atleast L+1. So these people will always report a value >= L+1

    So, if for some value of liars = L, if you are able to find exactly L people who say liars are > L then that means that L is actually the correct no. of liars.

    You can iterate over all all possible values of L and check.

    AC submission: 204649911

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

      4

      2 2 2 2

      plz explain this test case nksrivastava18

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

        Let's break it down into 2 subcases.

        Claim 1: Let's say the 1st person is not a liar. Therefore his statement is true. So out of the leftover 3 people, the number of liars should be atleast 2. So either 2 of them are liars or all 3 are liars. If only 2 of them are liars, they should lie and report atleast 3 as their answer. Since this is not the case, all 3 of them should be liars. Because all 3 are liars, they should lie and report that there are atleast 4 liars. Since even this is not the case, therefore our claim 1 is false.

        Now we are only left with the option that 1st person is a liar. Let this be claim 2. Since he is a liar, his statement is false. Therefore the no. of liars should be strictly less than 2. But since we are still left with 3 people who are saying the no. of liars should be atleast 2, therefore these 3 should also be liars. This is a contradiction and hence claim 2 is also false.

        Hence we can conclude that all of them are contradicting each other and return -1 as the answer.

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

      But isn't it always possible that everyone lies? (No. of liars is N)

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

    Which part don't you understand?

    Assume the number of liars is $$$x$$$. Then all people who said that the number of liars was greater than $$$x$$$ were lying! So to count how many liars there actually are, you need to count the number of $$$A[i] > x$$$ (note that $$$A[i] = y$$$ means the i-th person claims there are at least $$$y$$$ liars).

    It's easy to turn this into an $$$O(N^2)$$$ solution. The challenge is then to optimize this into an $$$O(N log N)$$$ solution.

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

      Still not getting the logic. Why do we need to count A[i] > x?

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

        People can only speak a falsehood by overestimating the number of liars, not by underestimating, since each person only makes a claim about the minimum number of liars there are.

        Let's look at a concrete example:

        • Anna says: at least 1 person lied!
        • Bernd says: at least 3 people lied!
        • Charity says: at least 0 people lied!

        Then there are four possibilities:

        • Maybe 0 people lied. But that cannot be true, because if 0 people lied, then Charity was speaking the truth, but Anna and Bernd were both lying about the number of liars, so there are 2 liars, not 0.

        • Maybe 1 person lied. In that case, Anna and Charity are speaking the truth, and Bernd is the sole liar, which is consistent.

        • Maybe 2 people lied. But that cannot be true, because in that case, Charity and Anna are speaking the truth, and Bernd is lying, so there is only 1 liar, not 2.

        • Maybe 3 people lied. But that cannot be true, because in that case, all three people are speaking the truth, so there 0 liars, not 3.

        So the only valid choice in this case is $$$x=1$$$.

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

      4

      2 2 2 2

      plz explain this test case

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

Petition: set at least 2.5-3 seconds time limit when the intended solution requires >1e8 operations. :)))

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

    Which problem are you referring to?

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

      Problem E surely, where the correct solution is $$$O(N^2 M)$$$ with N=5000 and M=500, which makes for $$$125 × 10^8$$$ operations, though processing 64 bits at a time is supposed to bring that down to $$$~1.95 × 10^8$$$.

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

        That's the problem with this type of tasks
        You can't cut off all the unintended solutions without cutting off some of the slower intended ones
        My fastest solution was faster than 500ms, so a 2s TL is only fair

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

          First of all, thanks for the wonderful round.
          I just wanted to say that solving the problem shouldn't be about being "risky" enough ddd.

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

For A, in the case that everyone says that nobody lied, then everyone may have lied, but that is not an accepted answer.

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

    The people cannot say that nobody lied. They would be saying "at least 0 people lied" which is obivously always true (it's impossible for less than 0 people to lie). Thus if everyone says this, everyone must speak the truth and the number of liars must be 0.

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

Can anyone give submission link for recursive dp solution of problem D?

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

I had a somewhat different solution for Problem B, which I'm not sure whether it was intended to pass or not.

Like the official solution, I consider the pairs of numbers that must be made equal (first and last element of A, second and second-to-last element of A, etc.), ignoring the numbers that are already equal (if all are equal, the answer is 0). For the first pair {a, b}, calculate all possible divisors of $$$a - b$$$. Then for each other pair {c, d}, filter down the possible divisors by checking if each divisor is also a divisor of $$$c - d$$$. (submission source code).

This solution is $$$O(sqrt(10^9) + N×k)$$$ where $$$k$$$ is the maximum number of divisors of a number below 10^9 which is around 1000, for an overall ~100,000,000 iterations.

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

bad contest

problems were not clear or understandable

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

Task E is cool, thanks!

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

May I know if it's possible to do problem A faster than brute force and how to do so?

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

    You can do it in n log(n). The idea is that if someone saying that there are at least 10 liars is saying the truth, then everyone else saying there are 1,2,...,9 liars will also be saying the truth. So you can iteratively check if exactly the first n people are saying the truth or not in O(n) after sorting.

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

E can be solved in O(nmlogn). we can build a binary index tree for every city.First, we sort all the models by their beauty in every cities(the first city has the largets weight the second has the second largets ...). then, we can do dp with this order( any reverse in this order is invalid!). When dp, for a model i,we can query every binary index tree for every city to get their previous max dp. for those maximum dp values we choose the minimum one for that one is the valid one.(unfortunately I fst cuz I for got that std::sort is weak sortings qwq)my code

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

What a WAnderful contest, I gained so much~

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

What is wrong in this this method for C

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

for problem F, the output format of my code is correct in my computer, but I get a WA because "wrong output format Unexpected end of file — double expected". what's up?

204643420

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

If I try to see the implementation it says: You are not allowed to view the requested page. What should I do?

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

Unable to open C++ implementation

"You are not allowed to view the requested page"

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

I was not able to solve B. Now my rating is a palindrome too xD

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

Can D be done without dp??

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

Hey, the C++ Implementation's link in problem A is blocked.

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

What is the distinction between a lie and a contradiction?

6
3 3 3 5 5 6

The above test case gives 3 as answer even though what the 4th element is saying is never possible.

In the same sense:

9
0 1 1 2 2 4 7 8 9

The last 2 says there are atleast 2 liars, and he's right, there are 4 liars, because what the first 4 is saying can never happen. But here the answer is -1. Can somebody explain? TIA

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

    In your second example statements of the first 5 people stay consistent with the previous statements, but the 6th person, who is saying that at least 4 people are lying contradicts himself and the rest of the statements, he can't either be lying or telling the truth.

    If the first 5 people are telling the truth then it means that there should be at least 2 and at most 4 liars in the group. Then if the 6th person is telling the truth that actually means that he should be one of the 4 people lying (a contradiction). If he is lying that means that there should be less than 4 total people lying in the group, therefore out of the last 3 people in the group at least 1 should be telling the truth (in turn meaning that there is at least 7 people lying or more, a contradiction).

    Hope this helps!

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

Не даёт посмотреть решение. Недостаточно прав для просмотра запрошенной страницы

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

why still I can't see the authors implementation?

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

My nlogn solution for A with a map: 204718789.

For the life of me couldn't figure out the brute force approach for A (although by looking at constraints it was obvious to me that n^2 should pass).

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

    I wrote also nlogn solution after contest (Virtual Contest) is over Just now after seeing your comment I just checked and saw n is 100 only :p.

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

Where does the number 64 come from in time complexity of Problem E. O(n^2m/64)

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

    The number of bits used by one number in a computer. In a 64 bit machine this number is 64. This number is often referred to as $$$W$$$, or wordlen.

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

    The operations on bitset has a complexity of O(N / K) , where N is the length of the bitset and K is the register size of the system (generally 32 or 64). Link

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

I am facing a weird behavior in problem F. I will query the 3rd line if the minimum distance between any projection of candidate points is at least EPS. When I set EPS = 1E-6 I get TLE, while EPS = 5E-4 will get AC in 200ms. However this is weird since smaller EPS means it is more likely to achieve the condition.

EPS = 1E-6 (TLE): 204744948

EPS = 5E-4 (AC): 204744799

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

How to solve problem D with the DP method

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

I started solving problem A as soon as the contest started. Gave up after an hour. Had dinner. Started again, thought of a binary search solution; didn't work, then i thought of a linear search solution(the correct one); couldn't implement it, i was just off by one line of code. Gave up. After the contest was over and i looked at the answer it was the hardest facepalm moment of my life.

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

Coding style is appreciable !!

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

My thoughts on problem F. Please correct me if you find any issues.

Theoretically, if we choose the degree of slope of our line uniformly in range $$$(0, \pi)$$$, the probability that two points fall on the same line should be 0, and choosing some random fixed slope should also work. However, there are about 200 tests. Consider if each one has $$$t=50$$$ cases, and each case has $$$n=10$$$ points, then the total number of vectors that can be formed is $$$200*50*10^4=10^8$$$. Denote our line as $$$w'x = b$$$, then the maximum of minimum angle between any vector and $$$w$$$ is $$$\frac{1}{2}\frac{ \pi}{10^8}$$$, and the smallest distance between projections of two points is $$$\sqrt{2} sin(0.5\frac{\pi}{10^8}) = 2e-8$$$. Now, this might still be distinguishable by double precision, but the problem can add a $$$1e-4$$$ noise to coordinates. If that noise is added in the direction parallel to our line (that is, orthogonal to $$$w$$$), then it is very easy to swap position of two projected points. Similarly, even if we randomize the slope each time, it is still unlikely to avoid all the vectors (I tried).

However, by the same analysis, if for each test case we choose the maximum possible minimum angle, then the smallest distance becomes $$$\sqrt{2} sin(0.5 \frac{\pi}{25^4 / 2}) = 1e-5$$$. Note that this is still smaller than $$$1e-4$$$. My first guess is that, since the $$$O(n^4)$$$ vectors are formed by choosing pairwise among $$$n^2$$$ points, it actually does not have enough freedom to uniformly spread among $$$(0, 2\pi)$$$, so the true gap is much larger than $$$2e-5$$$. This could be true, but the real reason is that, because all coordinates are in the range $$$(-100, 100)$$$, it is actually impossible for any vector angle to fall in range of, e.g. $$$(0, arctan(\frac{1}{200}))$$$, which is $$$2e-3$$$! This makes the problem completely trivial, as we can actually choose some fixed slope, e.g. $$$a=400, b=1$$$ should be the safest as it maximize the minimum gap. However, if this bound of $$$100$$$ is changed to $$$10000$$$, then we should still use the method by the editorial.

The $$$1e-3$$$ constraint does not matter as we can obtain coordinates from first two queries at the precision of $$$1e-4$$$.

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

The editorial says it has a fairly straightforward DP solution, but I feel, most of the people who solved it, skipped the mathematical proof of why it is okay to take the max $$$(b_l + l)$$$, thus converting the problem from find the max 3 elements and subtract $$$(r - l)$$$; to given an array, maximize $$$(b_l + l) + b_m + (b_r - r)$$$.

Proof: Let's say for a given $$$b_m$$$ there exists a $$$b_{l_1}$$$ and $$$b_{l_2}$$$ such that $$$b_{l_1} + l_1 < b_{l_2} + {l_2}$$$; given $$$l_2 > l_1$$$ and $$$b_{l_1} > b_{l_2}$$$. But in our segment, we have to take the maximum element so if $$$b_{l_1}$$$ stays we'll have to accept the value calculated using it. But we safely use $$$b_{l_2}$$$ which returns a higher value.

But this doesn't always work.

What if the question asked you to maximize $$$(b_l - l) + b_m + (b_r + r)$$$? I have seen some solutions for D, where people have tried looking for previous state of DP using LastGreater element, and I thought I am not the only one who doesn't find it straightforward.

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

"A more straightforward one, is checking all the numbers from 2 up to √n"

Hi can you please help me understand why we didn't go till n.

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

Can you please provide the dp approach for problem D. I understood the direct approach, I would really appreciate the help and thanks a lot for the effort.

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

Problem D , DP solution please explain!

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

why solution of O(m) getting TLE for problem C

bool f(ll n, ll m){ if (n == 1) return true; if (m >= n) return false; while (m > 1){ if (n % m == 0) return false; m--; } return true; }

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

Why does this approach doesn't work? This solution is more nature for me than GCD one. It's not the TLE, but the answer isn't correct and I can't see failure testcase. Thanks for future replying!

n = int(input()) d = list(map(int, input().split())) mx_mod = max(d) if mx_mod == 0: print(0) continue flag = True for i in range(n // 2): if d[i] != d[-i — 1]: flag = False while d[i] % mx_mod != d[-i — 1] % mx_mod: mx_mod -= 1 if flag: mx_mod = 0 print(mx_mod)

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

    Your code fails on

    Input:
    1
    5
    1 1 1 3 4
    
    Correct Output:
    1
    
    Your Output:
    2
    
    

    Array $$$[1, 1, 1, 3, 4]$$$ becomes $$$[1, 1, 1, 1, 0]$$$ when calculating all values $$$\bmod 2$$$, which is clearly not a palindrome.

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

Problem $$$E$$$ can also be cheesed.

The crux of the problem is to efficiently determine if model $$$i$$$ can go before model $$$j$$$. To do this, we know that:

(1) If $$$sum[i] + n > sum[j]$$$, then we know that model $$$i$$$ cannot come before $$$j$$$.

(2) If $$$mx[i] \ge mx[j]$$$, then model $$$i$$$ cannot come before $$$j$$$, where $$$mx[i]$$$ is the max rating of the $$$i$$$th model. Likewise, if $$$mn[i] \ge mn[j]$$$, then model $$$i$$$ cannot come before $$$j$$$.

Only if the above $$$3$$$ conditions are not met do we naively check the ratings in $$$O(m)$$$ time.

Once we check these constraints, we know that model $$$i$$$ must go before model $$$j$$$. But we also know that all models that come before model $$$j$$$ must also come before model $$$i$$$, so we add those to the graph.

Apparently, this approach passes. 211357168

Would be interested if someone could hack me...

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

For Problem D, I tried using a two-pointer approach, basically moving l or r depending on which value is smaller. Now instead of repeatedly computing maximum in [l,r] , I maintained 3 variables m1,m2,m3 and adjusted accordingly. Here is my implementation.

It is failing on tc 4, can someone help me figuring the error please ?

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

Hello guys i know it's been a while for this div but i have an idea on D that got me ACC so we can make it using seg tree because b1+b3+b2-(r-l) to be maximized we can see it like this : (b1+l)+b2+(b3-r) and for every element from 2 to n-1 we can get max element which is (bj+j) and j from 1 to i-1 and max (bc-c) where c from i+1 to n so result will be max(bi+max(bj+j)+max(bc-c)) and we can query using the seg tree to see the two element we are looking for because both B1 and B3 needs to be the left and right itself

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

    Read the editorial
    You don't even need segtree, just prefix/suffix maximum

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

      yes yes using pref and suff more easier just the idea didn't came